Server side pagination problems

Server side pagination problems

rhymesrhymes Posts: 2Questions: 0Answers: 0

I'm trying (and failing) at using DataTables for server side pagination.

Can you help me?

Client:

$('.js-devices-table').DataTable({
serverside: true,
processing: true,
deferRender: true,
lengthChange: false,
ajax: {
url: $('.js-devices-table').data('url'),
contentType: 'application/json; charset=utf-8'
},
columns: [
{data: 'uuid'},
{data: 'path'},
{data: 'platform'},
{data: 'os_version'},
{data: 'app_version'},
{data: 'notifications_enabled'},
{data: 'created_at'},
{data: 'updated_at'}
],
columnDefs: [
{
targets: 0, // uuid
render: function(data, type, row) {
var $link = $('<a/>').attr('href', row.path).text(row.uuid);
return $link.prop('outerHTML');
}
},
{
targets: 1, // path
visible: false
},
{
targets: 5, // notifications enabled
render: function(data, type, row) {
if (row.notifications_enabled === true) {
var $i = $('<i/>')
.attr('class', 'fa fa-check')
.attr('aria-hidden', 'true');
return $i.prop('outerHTML');
} else {
return '';
}
}
}
],
order: [[6, 'desc']] // order by created_at desc
});

JSON returned by the server:

{
"draw": 1,
"recordsTotal": 197,
"recordsFiltered": 197,
"data": [
{
"uuid": "bfe8e81c-d411-47ff-a127-fce76c070ae7",
"path": "/apps/8/devices/bfe8e81c-d411-47ff-a127-fce76c070ae7",
"platform": "ios",
"os_version": "Version 9.2.1 (Build 13D15)",
"app_version": "1.0",
"notifications_enabled": false,
"created_at": "2016-04-06T11:17:31.363+02:00",
"updated_at": "2016-04-06T11:17:31.363+02:00"
},
{
"uuid": "40207ad6-de7f-4f6f-90e8-7760dbf00fdf",
"path": "/apps/8/devices/40207ad6-de7f-4f6f-90e8-7760dbf00fdf",
"platform": "android",
"os_version": "22",
"app_version": "1.0",
"notifications_enabled": true,
"created_at": "2016-04-05T15:29:21.212+02:00",
"updated_at": "2016-04-05T15:29:21.212+02:00"
},
...
]
}

Each page has 25 records, DataTables shows them but the pagination controls are deactivated, it ignores the recordsTotal value I guess.

I am using DataTables 1.10.12 with Bootstrap 3.3.6 and jQuery 2.2.4

I posted the full debug here http://debug.datatables.net/ikexut

Thank you

Replies

  • Tom (DataTables)Tom (DataTables) Posts: 139Questions: 0Answers: 26

    On line 2 you've got a small typo when enabling serverSide.
    Just change serverside: true, to serverSide: true, and you should be good.

    Thanks

    Tom

  • rhymesrhymes Posts: 2Questions: 0Answers: 0

    Stupid typo! It works, thank you!

This discussion has been closed.