Multiple configurations for the same table

Multiple configurations for the same table

tciriptcirip Posts: 9Questions: 0Answers: 0
edited July 2009 in General

I have one table where columns change based on users input (something like SQL console). I reuse the same table and use following code to initialize the table:
$('#results_table').dataTable( {
"bAutoWidth" :true,
"bPaginate" :true,
"bInfo" :true,
"bFilter" :true,
"bSort": false,
"aoColumns": results.columns
} );

but then I get info, search, pagination and info multiple times for the same table, every time I run dataTable(). How should I use datatables to do what I need?




  • allanallan Posts: 60,304Questions: 1Answers: 9,791 Site admin
    HI Tomas,

    This is an interesting one. Re-initialisation of a Table is not something that is supported in DataTables (currently). What I would like to do sometime so it create a 'destructor' API function which when run will return the DOM to it's original state. This might be useful for you, but you might still run into problems with the varying columns given that DataTables gets the umber of columns from the DOM (unless you do something like this: ).

    What I would suggest in this case (unless you fancy writing a destructor function) is to wrap your table in a DIV (or whatever) and wipe it out each time you need to re-initialise it (innerHTML = ''; for example), and also nuke the old Javascript array (i.e. oTable = $(...).dataTable(...); and then delete oTable; when needed). Then you can just initialise the table as you did before (you'll need to add the table html if needed like in my demo above).

    How does that sound?
  • tciriptcirip Posts: 9Questions: 0Answers: 0

    You are amazing! Works like a charm.

    Thanks a lot!

This discussion has been closed.