OK, we've got some data from the server, and we've made the query run quickly, so now let's get onto pagination.
To get pagination working, we need to perform the data sorting on the server instead of the browser. It is not possible for the sorting to be done on the client side because in order to do that, the DataTables
plugin must have all of the sortable data in memory.
In table.html
, change the dataTable
call to this:
$('#the_table').dataTable({ 'bProcessing':true, 'bServerSide':true, 'sAjaxSource':'get_data.php' });
The bServerSide
parameter tells DataTables
to do all the processing on the server—that is, don't do any sorting or searching locally, as the browser does not have the information it needs to do this.
The bProcessing
parameter adds a small text message, processing, to the screen when it's retrieving the information from the server. You can use CSS to make this message more obvious if you want.