Reputation: 320
I need to add a delete icon to each row, and used the code below in "fnRowCallBack".
"fnRowCallback": function(nRow, aData, iDisplayIndex) {
if(addDeleteButton) {
var deleteIcon = $("<div>").addClass("ui-icon ui-icon-trash");
$("<td>").addClass("delete-icon").appendTo(nRow).html(deleteIcon);
}
}
But when "fnFilter" is used delete icon is a added to the row every time.
image.
How can I avoid this?
Upvotes: 0
Views: 549
Reputation: 51860
Datatable caches two things : the html (the nRow
nodes are kept in memory, not destroyed and recreated on each draw), and the data (the aData
is stored, if you modify it, you will still access the modifications later).
You need to check for some state which will signify "I have already added the icon to this row".
For example :
if(addDeleteButton && ($(nRow).find('.delete-icon').length == 0) ) { ... }
or :
if(addDeleteButton && !aData.deleteButtonAdded) {
aData.deleteButtonAdded = true;
...
}
Upvotes: 1