[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" } ]}
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" } ]}