editor tries to update all cells when I use AutoFill

editor tries to update all cells when I use AutoFill

Parc SanitariParc Sanitari Posts: 1Questions: 1Answers: 0
edited April 12 in Free community support

I'm using Autofill to update fields in my database. Everything is fine on the backend, but when I receive the response on the frontend I have the following error:

**DataTables warning: table id=inventario - Requested unknown parameter 'tipoElementoFisicoDescripcion' for row 6779, column 1. For more information about this error, please see https://datatables.net/tn/4**

Apparently, Datatable is trying to update the fields that were not sent. Is it possible to tell Datatable to only repaint the marca, modelo, partida item fields and ignore the other fields?

const autoFillEditor = new DataTable.Editor({
    ajax: '@Url.Action("EditRecord", "ElementoFisico")',
    idSrc: 'id',
    fields: [
        { name: 'marca' },
        { name: 'modelo' },
        { name: 'partida' }
    ],
    table: '#inventario'
});


var table = new DataTable('#inventario', {
    deferRender: true,
    processing: true,
    rowId: 'id',
    ajax: {
        url: '@Url.Action("GetRegistroList", "ElementoFisico")',
        type: 'GET',
        data: function (d) {
            d.nivel1Id = $('#Filtro_Nivel1Id').val();
            d.nivel2Id = $('#Filtro_Nivel2Id').val();
            d.nivel3Id = $('#Filtro_Nivel3Id').val();
            d.nivel4Id = $('#Filtro_Nivel4Id').val();
            return d;
        }
    },
    columns: [
        {
            sortable: false,
            render: function (data, type, full, met) {
                var result = '';
                result = `<a href="/ElementoFisico/Edit/${full.id}">
                              <i class="far fa-edit"></i>
                          </a>`;
                return result;
            }
        },
        { data: 'tipoElementoFisicoDescripcion' },
        { data: 'matricula' },
        { data: 'ubicacionAntiguoInventario' },
        { data: 'ubicacionObservaciones' },
        { data: 'observaciones' },
        { data: 'fechaAlta' },
        { data: 'marca' },
        { data: 'modelo' },
        { data: 'proveedorCodigo' },
        { data: 'fechaFactura' },
        { data: 'fechaFinGarantia' },
        { data: 'estadoDescripcion' },
        { data: 'numeroSerie' },
        { data: 'persona' },
        { data: 'personaAntiguo' },
        { data: 'precio' },
        { data: 'departamentoCodigo' },
        { data: 'departamentoAntiguo' },
        { data: 'elementoInmovilizado' },
        { data: 'propietarioCodigo' },
        { data: 'partida' },
            {
            data: 'id',
            visible: false
        }
    ],
    autoFill: {
        horizontal: false,
        columns: ':not(:first-child)',
        editor: autoFillEditor
    },
    ...


backend:
using (var db = new Database(dbType, dbConnection))
{
    var editor = new Editor(db, TableName)
        .Model<ElementoFisicoAutoFillModel>()
        .Field(new Field("marca").Xss(false))
        .Field(new Field("modelo").Xss(false))
        .Field(new Field("partida").Xss(false));
    editor.PreRemove += (sender, args) => args.Cancel = true;
    var response = editor
        .Process(request, culture: "es-ES")
        .Data();

    return response;
}
Sign In or Register to comment.