How To Add RowId and RowClass on Datatable

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,

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.

datatable_rowid

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>

2 thoughts on “How To Add RowId and RowClass on Datatable

    • 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.

Leave a Reply

Your email address will not be published. Required fields are marked *