DataTables server-side processing example - automatic row ID addition

[url]http://datatables.net/release-datatables/examples/server_side/ids.html[/url]

Often when using server-side processing you will find that it can be useful to have a specific ID on each row (the row ID from the database for example). By assigning the ID you want to apply to each row using the property DT_RowId of the data source object for each row, DataTables will automatically add it for you. Likewise there is a DT_RowClass option which will add your given class. This example shows both and is a trivial modification of the server-side script to add these two options, with no changes on the client-side.


Initialisation code


$(document).ready(function() { $('#example').dataTable( { "bProcessing": true, "bServerSide": true, "sAjaxSource": "scripts/id.php" } );} );

Server response

The code below shows the latest JSON data that has been returned from the server in response to the Ajax request made by DataTables. This will update as further requests are made.


{ "sEcho": 2, "iTotalRecords": "57", "iTotalDisplayRecords": "57", "aaData": [ { "0": "Gecko", "1": "Mozilla 1.1", "2": "Win 95+ / OSX.1+", "3": "1.1", "4": "A", "DT_RowId": "row_17", "DT_RowClass": "gradeA" }, { "0": "Gecko", "1": "Mozilla 1.2", "2": "Win 95+ / OSX.1+", "3": "1.2", "4": "A", "DT_RowId": "row_18", "DT_RowClass": "gradeA" }, { "0": "Gecko", "1": "Mozilla 1.3", "2": "Win 95+ / OSX.1+", "3": "1.3", "4": "A", "DT_RowId": "row_19", "DT_RowClass": "gradeA" }, { "0": "Gecko", "1": "Mozilla 1.4", "2": "Win 95+ / OSX.1+", "3": "1.4", "4": "A", "DT_RowId": "row_20", "DT_RowClass": "gradeA" }, { "0": "Gecko", "1": "Mozilla 1.5", "2": "Win 95+ / OSX.1+", "3": "1.5", "4": "A", "DT_RowId": "row_21", "DT_RowClass": "gradeA" }, { "0": "Gecko", "1": "Mozilla 1.6", "2": "Win 95+ / OSX.1+", "3": "1.6", "4": "A", "DT_RowId": "row_22", "DT_RowClass": "gradeA" }, { "0": "Gecko", "1": "Mozilla 1.7", "2": "Win 98+ / OSX.1+", "3": "1.7", "4": "A", "DT_RowId": "row_23", "DT_RowClass": "gradeA" }, { "0": "Gecko", "1": "Mozilla 1.8", "2": "Win 98+ / OSX.1+", "3": "1.8", "4": "A", "DT_RowId": "row_24", "DT_RowClass": "gradeA" }, { "0": "Gecko", "1": "Seamonkey 1.1", "2": "Win 98+ / OSX.2+", "3": "1.8", "4": "A", "DT_RowId": "row_25", "DT_RowClass": "gradeA" }, { "0": "Gecko", "1": "Epiphany 2.20", "2": "Gnome", "3": "1.8", "4": "A", "DT_RowId": "row_26", "DT_RowClass": "gradeA" } ]}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值