Swap tables - dynamic columns

Swap tables - dynamic columns

MisiuMisiu Posts: 68Questions: 4Answers: 2
edited March 2014 in DataTables 1.10
In my application I have table that can have multiple columns, based on date range selected.
I need to be able to display table containing 20 columns or 50 columns. I did that, but I was refreshing page when my parameters changed.
Now I'm trying to do it better.

I've created sample that shows my approach: http://live.datatables.net/fojusec/3/edit

Basically I'm swapping "table" with new content that comes from ajax request and then I'm calling "dataTable" on that new table.
My example works fine, but I was wondering if maybe there is a better way to do it, maybe by reconfiguring table?

Is it safe to do that like I did? I'm worried about any leaks.

EDIT:
What I'm not sure is if dataTable object is attached to table. So if I'm removing table from DOM I should be removing dataTable object also.
I would like to avoid any conflicts. I clicked on my example for some time and I didn't got any errors.

Replies

  • MisiuMisiu Posts: 68Questions: 4Answers: 2
    Can I safety replace div containing table content and then call dataTable() on new content?
    For now we can't reconfigure dataTable so I think this is the only option.
    Allan any better way of doing this?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Your approach looks okay. If you are just change the data, then using the API to add and delete rows is the way to do it, but if you want to change the columns or table options you need to replace the old table.

    I would suggest that you destroy the old table first, otherwise you'll have a memory leak. fnDestroy in 1.9- and `destroy()` in 1.10+.

    Allan
This discussion has been closed.