editor serverSide code error!!

editor serverSide code error!!

moonoo1moonoo1 Posts: 11Questions: 6Answers: 0

I am practicing step by setp the samples of the editor version.
I am applying serverside to the 1st example link.

https://editor.datatables.net/examples/simple/simple.html

I added the code below and got the message below

err message : DataTables warning: table id=example - Unknown field: (index 0)

$('#example').DataTable( {
dom: "Bfrtip",
//ajax: "../../controllers/staff.php",
ajax: {
url : "../../controllers/staff.php",
type: "POST" // <== here!!
},

    processing: true,   // <== here!!
    serverSide: true,   // <== here!!

    columns: [
        { data: null,
          searchable:false,     // <== here!!
          render: function ( data, type, row ) {
            // Combine the first and last names into a single table field
            return data.first_name+' '+data.last_name;
        } },
        { data: "position" },
        { data: "office" },
        { data: "extn" },
        { data: "start_date" },
        { data: "salary", render: $.fn.dataTable.render.number( ',', '.', 0, '$' ) }
    ],
    select: true,
    buttons: [
        { extend: "create", editor: editor },
        { extend: "edit",   editor: editor },
        { extend: "remove", editor: editor }
    ]
} );

I've tried modifying the code, but I'm still getting the error message
==> searchable:false,
What's wrong?
Please correct my code.

Replies

  • allanallan Posts: 63,446Questions: 1Answers: 10,465 Site admin

    You've enabled server-side processing which is causing the issue. It needs to map a column's data on the client-side to the data on the server-side, so operations such as ordering and filtering.

    In this case, the default ordering is on the first column (order), which it can't do since data: null is used. You could make it data: 'last_name' if you wanted sort and filter to be done on the last name only.

    Have a look at this example for a working example with server-side processing.

    Allan

Sign In or Register to comment.