How do I customize HTML attributes for a row that is added via row.add( ) ?
How do I customize HTML attributes for a row that is added via row.add( ) ?
HI all,
How do I customize HTML attributes (i.e. class & data-attribute) for a row that is added via row.add() function?
i.e. I want to add a class and data-order to the 3rd column ( i.e. <td> ) of each row added for sorting.
Since we cannot include and pass the <td>/<tr> markup to the row.add(), I can only define the inner HTML tags inside <td> for each column but not the <td> itself.
Say I have an array of objects as data source, and I use a for-loop to add a new row to the table with data in each of the objects. I tried to use jQuery to locate the latest added row and then add class/data-attributes after the row.add( ).draw( ), but the order for locating the last added row is always messed up.
I thought a newly added row (i.e. tr) is always the last child of the tbody? But it doesn't seem like it. What should be the correct jQuery selector to locate it?
Thus, even though I add data-order="number" to the <td> later on with jQuery, the data-order sorting still doesn't work. (The table still looks up the text of the column)
Please kindly assist. Thank you very much!!!
-Anthony
Answers
You can use either
createdRow
orrowCallback
. According to the docscreatedRow
might be more efficient.Kevin
One more option is that you can pass the
tr
element intorow.add()
with the element attributes setup as you require already.Allan