Refresh Table after adding, replacing or removing rows from the table

Refresh Table after adding, replacing or removing rows from the table

WornWorn Posts: 7Questions: 0Answers: 0
edited August 2012 in General
Hi,

I´m new to dataTables. I´m a bit confused because I can not find a solution to update the table after adding, replacing or removing rows from my table. I need to explain why I want to use this. First I load a table from my server. Then I bind dataTables and everything looks fine. Then I add some data to my backend-database and I´m using handlebars-templates to create the html for the new row. I want to use this because I want to reuse my javascript for a lot of different tables. While initializing the JS I store information about which handlebars template to use for the current table. So I can simply throw the response from the server to the template and I get a perfecly new TR depending on the response information.

As I cannot find a solution to just update the dataTable based on the DOM elements I wonder if this is possible. I found the "fnAddTr" API function, This could do the trick... but I´m missing fnUpdateTr and fnRemoveTr.. or am I understanding something wrong?

Could someone help me out?
Thanks

Worn

Replies

  • WornWorn Posts: 7Questions: 0Answers: 0
    Hi again,

    got adding and deleting. But I still need to update a row. I would like to kind of replace one TR with another through dataTables. Is this possible somehow?

    Thank you!

    Worn
  • WornWorn Posts: 7Questions: 0Answers: 0
    Hi again,

    got this working now. I think it´s not the cleanest way but it works fine for me (I did not want to alter the whole structure because of using datatables..).

    I use the "fnAddTr" API function to add TR Elements to the table (they are created by handlebars templates). Row delete works fine with fnDeleteRow($myRow[0]) where $myRow[0] is a jQuery object containing the TR element. And finally row replacement is a combination of both.. first delete then add like described. As jQuery´s replaceWith function (I used before) does it the same way I think it´s okay.

    So fnAddTr is the trick like I thought already in my very first post :-).

    so long...

    Worn
This discussion has been closed.