Previous post we have learn how to use DataTables Example with PHP,in this article we will learn how to add rowid and rowclass with each row into data table.Some times we need to identify each row based on id or row class.Jquery datatable has many properties for easy handle datatable with server side.
Also Checkout other tutorial of Datatable,
- Part 1: Introduction of Datatable
- Part 2- DataTables Example – Server-side Processing with PHP
- Part 3 – How to add RowId and RowClass on each record using Datatable
- Part 4 – Datatable Pagination, Sorting and Search – Server Side (PHP/MySQl) Using Ajax
- Part5 – Export the jQuery Datatable data to PDF,Excel,CSV and Copy
- Part 6 – Datatable Responsive – Using PHP and Mysql with Ajax
The following are three properties which is used to identify unique each row.
- {string} DT_RowId – Add an ID to the TR element.
- {string} DT_RowClass – Add a class name to the TR element.
- {object} DT_RowData – Add HTML5 data- attributes to the TR element. This is an object of key / value pairs which are assigned as data attributes to the TR element.
How To Add RowId on Each Row in Datatable :
We will add id on each row of table using below syntax.
array("DT_RowId"=> "6",'Name'=>'parvez', 'Empid'=>11, 'Salary'=>101)
with help of above code, you can see ‘6’ id has been attached against with ‘parvez’ row data like below,
<tr id="6"><td>Parvez<td> ...</tr>
where to put this array. Please give the example code if you can
Hi Nadeem,
You need to create your rows data as like array(“DT_RowId”=> “6”,’Name’=>’parvez’, ‘Empid’=>11, ‘Salary’=>101),as per my understanding u do not have DT_RowId col in ur reponse, so u need to add DT_RowId col in php response.