Datatables Server-Side Parameter Set

Server-side processing is enabled by use of the serverSideDT option, and configured usingajaxDT. See below for further information on configuration options.

Sent parameters

When making a request to the server using server-side processing, DataTables will send the following data in order to let the server know what data is required:

The order[i] and columns[i] parameters that are sent to the server are arrays of information:

  • order[i] - is an array defining how many columns are being ordered upon - i.e. if the array length is 1, then a single column sort is being performed, otherwise a multi-column sort is being performed.
  • columns[i] - an array defining all columns in the table.

In both cases, i is an integer which will change to indicate the array value. In most modern server-side scripting environments this data will automatically be available to you as an array.

Returned data

Once DataTables has made a request for data, with the above parameters sent to the server, it expects JSON data to be returned to it, with the following parameters set:

In addition to the above parameters which control the overall table, DataTables can use the following optional parameters on each individual row's data source object to perform automatic actions for you:

An example of how a return looks using these options is shown below in the "Example data" section below.

Configuration

Server-side processing in DataTables is enable through use of the serverSideDT option. Simply set it to true and DataTabels will operate in server-side processing mode. You will also want to use the ajaxDT option to specify the URL where DataTables should get its Ajax data from. As such, the simplest server-side processing initialisation is:

 
1
2
3
4
$( '#example' ).DataTable( {
     serverSide:  true ,
     ajax:  '/data-source'
} );

Configuration of how DataTables makes the Ajax request is configured through the ajaxDT option. In the above example we used it as a string, which instructs DataTables to use its default settings for making the Ajax request. However, you can customise these settings by passing ajaxDT in as an object. As an object, ajaxDT maps directly onto the jQuery ajax configuration object, so any options you can use in a jQuery request, you can also use with DataTables! For example, to make a POST request:

 
1
2
3
4
5
6
7
$( '#example' ).DataTable( {
     serverSide:  true ,
     ajax: {
         url:  '/data-source' ,
         type:  'POST'
     }
} );

For further information about the Ajax options available in DataTables, please refer to the ajaxDTdocumentation.

Legacy

Older versions of DataTables (1.9-) used a different set of parameters to send and receive from the server. As such scripts which are written for DataTables 1.10+ will not be able to function with DataTables 1.9-. However, DataTables 1.10 does have a compatibility mode for scripts written for 1.9-. This compatibility mode is triggered by use of the old sAjaxSource parameter (rather than the new ajaxDT parameter) or by setting $.fn.dataTable.ext.legacy.ajax = true; .

For documentation on the 1.9- method of performing server-side processing, please refer to thelegacy documentation.

Example data

Example of server-side processing return using arrays as the data source for the table (full example):

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
     "draw" : 1,
     "recordsTotal" : 57,
     "recordsFiltered" : 57,
     "data" : [
         [
             "Angelica" ,
             "Ramos" ,
             "System Architect" ,
             "London" ,
             "9th Oct 09" ,
             "$2,875"
         ],
         [
             "Ashton" ,
             "Cox" ,
             "Technical Author" ,
             "San Francisco" ,
             "12th Jan 09" ,
             "$4,800"
         ],
         ...
     ]
}

Example of server-side processing return using objects, with DT_RowId and DT_RowData also included, as the data source for the table (full example):

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{
     "draw" : 1,
     "recordsTotal" : 57,
     "recordsFiltered" : 57,
     "data" : [
         {
             "DT_RowId" "row_3" ,
             "DT_RowData" : {
                 "pkey" : 3
             },
             "first_name" "Angelica" ,
             "last_name" "Ramos" ,
             "position" "System Architect" ,
             "office" "London" ,
             "start_date" "9th Oct 09" ,
             "salary" "$2,875"
         },
         {
             "DT_RowId" "row_17" ,
             "DT_RowData" : {
                 "pkey" : 17
             },
             "first_name" "Ashton" ,
             "last_name" "Cox" ,
             "position" "Technical Author" ,
             "office" "San Francisco" ,
             "start_date" "12th Jan 09" ,
             "salary" "$4,800"
         },
         ...
     ]
}

A full set of examples, exploring the options available for server-side processing is available in theexamples section of this site.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值