Duplicate row when doing Add row

Duplicate row when doing Add row

chalkegchalkeg Posts: 6Questions: 3Answers: 0
edited May 2016 in Free community support

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);
            });
            }

Answers

  • chalkegchalkeg Posts: 6Questions: 3Answers: 0

    Following coding is now removing old row and updating new row with class

           function updateTable(listName)
           {
            var siteUrl = _spPageContextInfo.webAbsoluteUrl;
    
            var tableName = $('#patrol').DataTable();
                var oldNode = tableName.$("td:contains('"+itemId+"')").parent('tr');
                tableName.row(oldNode).remove();
                tableName.row(oldNode).invalidate();
                console.log("Record Deleted");
    
            getListItemWithId(itemId,listName,siteUrl,function(data){
                tableName.row.add( data ).draw();
    
    
                var newnode = tableName.$("td:contains('"+itemId+"')").parent('tr');
    
                $(newnode).addClass('newrow');
                },              
                function (error) {
                console.log(error);
                });
                  }
    
This discussion has been closed.