Dynamic tbody isn't recognized by datatables

Dynamic tbody isn't recognized by datatables

Lone ShepherdLone Shepherd Posts: 11Questions: 0Answers: 0
edited July 2010 in General
I've got a page where I initialize a datatable object with a blank tbody. Then a jquery function calls an ajax form (with some params from controls on the page) to load data into tbody.

The content gets updated, but the rows are not styled. Also, when I click on any of the headers to sort, all the table data disappears and it shows the "empty table" text.

I'm not sure how to tell datatables that there is new content in the table. What's the best way to do this?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    To insert new data in a DataTable use the fnAddData API function: http://datatables.net/api#fnAddData . An alternative option (the hammer approach) would be to destroy the old DataTable, update the DOM as you wish and then initialise the DataTable again (the 1.7 betas introduce a fnDestroy() API function).

    The reason for this requirement is that DataTables needs to be told about the new data so it can be processed and stored. It's not currently possible to put a DOM event listener on the table and see what new data is added (which would be the ideal way).

    Allan
  • Lone ShepherdLone Shepherd Posts: 11Questions: 0Answers: 0
    Hi Allan,

    thanks for the timely response -- I must have missed that function when browsing the docs!

    Nice plugin, by the way ;)
This discussion has been closed.