Add className or Id to columns in Datatable
Add className or Id to columns in Datatable

var topTable = $('#topTable').DataTable();
dataResult.map((eachData,index) => {
topTable.row.add([ eachData.id, eachData.name, eachData.dep])
}
topTable.draw()
I want to add classname or id class="name-"+index to the columns, such that
tr
td
td(class="name-0) name
td
tr
td
td(class="name-1)
td
This discussion has been closed.
Answers
Use
columns.createdCell
orcolumns.createdRow
.Kevin
How can that be done in my example
var topTable = $('#topTable').DataTable();
dataResult.map((eachData,index) => {
topTable.row.add([ eachData.id, eachData.name, eachData.dep])
}
I need something like
dataResult.map((eachData,index) => {
var rowData = topTable.row.add([ eachData.id, eachData.name, eachData.dep]).node()
$(rowData).childNode[1];
}
Did you look at the example in the docs for
createdRow
? It has an example of adding a classname to each row. This example usesrowCallback
but its same idea withcreatedRow
. If you need specific help the please build a simple test case showing what you have so we can provide a specific solution.https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin