0

I able to add id to each row of data table using rowId ,as explained in documentation.

$('#myTable').DataTable( {
    ajax: '/api/staff',
    rowId: 'staffId'
} );

But how do I add data-* attributes to the row.

For example I want to have add data-spaceid and ata-enrollmentid to the row.

<tr data-spaceid="20146" data-enrollmentid="32" id="123"/>
1

1 Answer 1

1

use createdRow, Callback for whenever a TR element is created for the table's body to add data attribute. Here is an example.

$('#myTable').dataTable( {
  'createdRow': function( row, data, dataIndex ) {
      $(row).attr('data-spaceid', '20146');
  },
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.