Add class to all cells, not just first page results
Add class to all cells, not just first page results
tahoma403
Posts: 3Questions: 2Answers: 0
I have no control over the creation/configuration of my DataTable, so I'm using this script to add classes to the table cells:
$("table").on('init.dt',function(){
$("td").addClass("td-styles");
});
But it only works for the table displayed on the first page - when I click "Next" to display more results, the classes are not applied. Is there a way to add it to the entire table?
This question has an accepted answers - jump to answer
Answers
You can achieve this with https://datatables.net/reference/option/columns.createdCell
If you aren't able to add configuration options, you'll need to listen for the
draw
event and each time it happens, run the code again. Just changeinit.dt
todraw.dt
and that should do it.Allan