Server-side processing

Select 2.1 introduced support for server-side processing - there is special consideration here as the row selection is client-side, but not all rows are available at the client-side (only those drawn for the current display). This has an impact on the API as .rows({selected: true}) will only be able to fetch information about the rows that are currently display.

To address this, Select introduces the select.cumulative() method which can be used to get the ids of all rows that are selected, regardless of paging or filtering. Note that the data source must have a unique id per row and you may have to se the rowId option to tell DataTables what it is called (it looks for DT_RowId by default).

Additionally, the selectAll button and checkbox header (when used with checkbox selection) will only select the currently displayed rows. This is because the client-side can't know what other rows there are that can be selected.

This example let's you experiment with Select when server-side processing is enabled.

First name Last name Position Office Start date Salary
First name Last name Position Office Start date Salary
  • Javascript
  • HTML
  • CSS
  • Ajax
  • Server-side script
  • Comments

The Javascript shown below is used to initialise the table shown in this example:

$('#example').DataTable({ ajax: '../../../../examples/server_side/scripts/ids-objects.php', columns: [ { data: 'first_name' }, { data: 'last_name' }, { data: 'position' }, { data: 'office' }, { data: 'start_date' }, { data: 'salary' } ], layout: { topStart: { buttons: [ 'pageLength', { text: 'View selection info', action: function (e, dt) { alert( 'Information about selected rows: '+ JSON.stringify(dt.select.cumulative()) ); } } ] } }, processing: true, select: true, serverSide: true });
new DataTable('#example', { ajax: '../../../../examples/server_side/scripts/ids-objects.php', columns: [ { data: 'first_name' }, { data: 'last_name' }, { data: 'position' }, { data: 'office' }, { data: 'start_date' }, { data: 'salary' } ], layout: { topStart: { buttons: [ 'pageLength', { text: 'View selected ids', action: function (e, dt) { alert( 'Information about selected rows: '+ JSON.stringify(dt.select.cumulative()) ); } }, 'selectAll', 'selectNone' ] } }, processing: true, select: true, serverSide: true });

In addition to the above code, the following Javascript library files are loaded for use in this example:

    The HTML shown below is the raw HTML table element, before it has been enhanced by DataTables:

    This example uses a little bit of additional CSS beyond what is loaded from the library files (below), in order to correctly display the table. The additional CSS used is shown below:

    The following CSS library files are loaded for use in this example to provide the styling of the table:

      This table loads data by Ajax. The latest data that has been loaded is shown below. This data will update automatically as any additional data is loaded.

      The script used to perform the server-side processing for this table is shown below. Please note that this is just an example script using PHP. Server-side processing scripts can be written in any language, using the protocol described in the DataTables documentation.

      Other examples