When using serverSide: true
all fields that aren't used by one of the columns are automatically removed from the JSON that's stored under table.data()
and cannot be accessed for further processing.
For example I have some custom rendering logic, that adds a star depending on another value's boolean.
table = $('#snowflake').DataTable({
ajax: {
url: "/api/entries/",
},
processing: true,
serverSide: true,
searchDelay: 1500,
rowId: 'id',
order: [[0, 'asc']],
columns: [
{
data: 'order',
className: 'reorder',
}, {
data: "name",
name: "name",
render: function(data, type, row) {
if (row.enabled) { // row.enabled will be undefined
return data + ' *';
}
return data;
}
},
],
});
JSON returned from server:
[{
"id": 1,
"order": 1,
"name": "Hello world",
"enabled": true
}, ...]
However because enabled
does not have a definition in columns
it's not accessible by the name
render
method, as it's automatically discarded/set to undefined
by DataTables.
Any idea how to keep all data returned from the server – just like it would, if we were using the normal, local non-serverSide
mode?
PS: More on a sidenote; is it possible to call table.draw()
without fetching the data from the API again? I just want to update column visibility.