I am dynamically adding a new row to DataTables 1.10.2 using the table.row.add() method using this code:
table.row.add([ '', name, target_l, details, panel.html() ]).draw();
I made this allowance:
<tr role="row" class="odd"> <th>1 .</th> <td class="sorting_1">ID Fee</td> <td>All students</td> <td></td> <td> <button class="btn btn-null btn-xs" onclick="_remove(59, 'ID Fee')"> <span class="fui-cross"></span> </button> <button class="btn btn-null btn-xs" onclick="_edit(59, 'ID Fee', '', '')"> <span class="icon-pencil"></span> </button> </td> </tr>
What I want to do is add an attribute (and other data) to the newly added tr tag (insert or add a row) and make it something like this:
<tr data-id="59" role="row" class="odd">
I managed to get the index of the added row using code and it returns the index of the last row:
var i = table.row.add([ '', name, target_l, details, panel.html() ]).index();
And also tried the following to add the data-id attribute using this index:
var id = $("#department_id").val(); table.row(i).attr("data-id", id);
I am new to DataTables and have already scrolled its source code, red comments. Although this does not well understand its functions, starting with _fn*() . If there is any other way without relying on these _fn*() functions, thanks!
Gideon
source share