2
votes

I am using the jQuery plugin called DataTables and I would like to display a table, that is populated automatically from an Ajax source, that supports pagination. The problem is that, from the server, I only get 10 results out of all the results (the response also contains the total number of results). Therefore the pagination looks something like : showing 1 to 10 out of 10 results.

I want it to say : showing 1 to 10 out of X results, where X is the total number of results. I cannot use any server side processing. So my question is :

How can I configure the DataTables plugin, to use this type of pagination ?

For example something like :

jQuery(table).dataTable({
  "aoColumnDefs": [...],
  "bProcessing" : true,
  "sAjaxSource" : "...",
  "sAjaxDataProp" : "...",

  "sOffsetParam" : "offset",
  "sNumFoundParam" : "totalResults"
});

Once again, I am restricted on working only on the client-side.

I managed to find a partial response :

If I set the "bServerSide" flag to TRUE, the plugin will look inside the server response for the fields required to build the pagination system. However, the field names are still hardcoded, so I still need a way to use custom field names. Also, the offset is sent using the "sEcho" parameter (which indicates the number of the page that is required).

1

1 Answers

0
votes

As you can see here the server must return two paramters

int - iTotalRecords - Total records, before filtering (i.e. the total number of records in the database) int - iTotalDisplayRecords - Total records, after filtering (i.e. the total number of records after filtering has been applied - not just the number of records being returned in this result set)

if the server doesn't return those parameters the client can't know that it must draw the next / prev buttons