Error trying to add row in datables.

0

Trying to add a row throws me the following error:

  

DataTables warning: table id = table - Request unknown parameter 'name' for row 0, column 1. For more information about this error, please see link

This is the datatables code

$(document).ready(function(){
            var table = $('#table').DataTable({
                "responsive": true,
                "processing": true,
                "serverSide": true,
                "ajax": "tabla/cargos",
                "columns": [
                    {
                        sortable: false,
                        "render": function ( data, type, full, meta ) {
                            return meta.row+1;
                        }
                    },
                    {data: 'nombre'},
                    {
                        sortable: false,
                        "render": function ( data, type, full, meta ) {
                            return '<button class="edit-modal btn btn-info" data-id="'+full.id+'" data-nombre="'+full.nombre+'">'+
                                    '<span class="fa fa-edit"></span> Editar'+
                                   '</button> '+
                                   '<button class="delete-modal btn btn-danger" data-id="'+full.id+'" data-nombre="'+full.nombre+'">'+
                                    '<span class="fa fa-trash"></span> Eliminar'+
                                   '</button>'
                            ;
                        }
                    },
                ],
                "language": idioma_español
            });
            new $.fn.dataTable.FixedHeader( table );

            $('#addRow').on( 'click', function () {
                table.row.add( [
                    '10',
                    'Prueba',
                    'Botones'
                ] ).draw( false );
            } );

            // Automatically add a first row of data
            $('#addRow').click();
        });
    
asked by Pablo Contreras 15.11.2016 в 16:59
source

2 answers

1
  

The error is warning you that you have not indicated the nombre property in the record you are trying to add.

As far as I can see, tabla/cargos returns an array of objects with the properties id and nombre .

With this info it occurs to me that a solution could be the following:

$('#addRow').on( 'click', function () {
  table.row.add({
   id: '10',
   nombre: 'Prueba',
   algo: 'Botones' // No sabria decir a que prop responde este valor.
  });
});
    
answered by 15.11.2016 / 21:50
source
0

I had the same problem and found the solution to place the names of the columns. With that he corrected himself.

{
            "bLengthChange": false,
            "bPaginate": true,
            "bInfo": false,
            "autoWidth": false,  
            "order": [[0, "desc"]],
            "processing": true,
            "serverSide": false,
            "sAjaxSource": "data.js",
            "columns": [
            { "data": "CustomerName" },
            { "data": "product" },
            { "data": "perticulars" },
            { "data": "AddressOfCustomer" },
            { "data": "ContactNumbers" }
        ]
        }

I found it at DataTables : table id = example - Requested unknown parameter '1' for row 1, column 1

    
answered by 16.10.2017 в 13:03