Empty table and reload Json data

Empty table and reload Json data

atiqulatiqul Posts: 2Questions: 1Answers: 0

My use case is that once I receive data from server side, I need to massage data (add a tags, classes, and the like) before I can add it to the table.

I can remove all data by using $("#example tbody").empty(); then I can use t.add().row([array]);
but this is slow also need to fix pagination

Is there a shortcut to that to empty table, add rows and adjust pagination?

Thanks,

-AI

Answers

  • allanallan Posts: 63,461Questions: 1Answers: 10,466 Site admin

    Can you show me the full code you are using please? I might be able to spot how it can be optimised.

    Allan

  • atiqulatiqul Posts: 2Questions: 1Answers: 0
    edited November 2017

    var tbl = $('#example').DataTable();
    //clear table
    tbl.rows().remove().draw(false);
    //add row one at a time
    tbl.row.add([ "Gavin Cortez", "Team Leader", "San Francisco", "2860", "2008/10/26", "$235,500" ]).draw(false);

  • allanallan Posts: 63,461Questions: 1Answers: 10,466 Site admin

    If you are calling draw() every time you use row.add(), then that's going to hurt performance a lot! Add all of the rows (presumably in a loop) and then use draw().

    Allan

This discussion has been closed.