Adding a row dynamically then deleting without refreshing the page seems to fail.

Adding a row dynamically then deleting without refreshing the page seems to fail.

BITSOLVERBITSOLVER Posts: 2Questions: 1Answers: 0

If I add a new row to a table eg (from an ajax response):

table.row.add({"id": data.id, "text": data.text}).draw();

This works fine, I see the new row.
But (assume id = 0) if I try and lookup the row to delete it with:

table.rows(function(idx, rowdata, node) {
    if ($.inArray(rowdata.id, removed) !== -1) {
        alert(rowdata.id)
    }
});

But if I refresh the page before deleting then the delete works.

I'm creating the datatable using object as rows so I can hide the id column.

To me it seems that adding a row is updating the DOM table but not updating the data model properly.

I'm using Django on the backend so I'm sending the ids of records to be deleted then returning ids that have successfully been deleted, all the responses are coming back as expected when debugging the ajax response.

Thanks in advance.
Steve

Answers

  • BITSOLVERBITSOLVER Posts: 2Questions: 1Answers: 0

    I've solved it. Stupid mistake, the id was added as a numeric and not a string. Calling

    id.toString();
    

    when adding the row fixed it.

    Thanks for a great project anyway,
    Steve

This discussion has been closed.