Duplicate row when doing Add row
Duplicate row when doing Add row

Hello,
I have a code which deletes existing row from the datatable (populated from Ajax source). This works as expected. However when i tried to add same row using fresh ajax call, it is inserting two records one with old values and another with new. debugger shows data object has only 1 record (updated record row).
function updateTable(listName) {
var siteUrl = _spPageContextInfo.webAbsoluteUrl;
var tableName = $('#patrol').DataTable();
tableName.$("td:contains('"+itemId+"')").parent('tr').remove();
console.log("Record Deleted");
getListItemWithId2(itemId,listName,siteUrl,function(data){
tableName.row.add( data );
var newnode = tableName.$("td:contains('"+itemId+"')").parent('tr');
tableName.row(newnode).invalidate().draw();
$(newnode).addClass('newrow');
},
function (error) {
console.log(error);
});
}
This discussion has been closed.
Answers
Following coding is now removing old row and updating new row with class