Multiple configurations for the same table

Multiple configurations for the same table

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

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:
[code]
$('#results_table').dataTable( {
"bAutoWidth" :true,
"bPaginate" :true,
"bInfo" :true,
"bFilter" :true,
"bSort": false,
"aaData": results.data,
"aoColumns": results.columns
} );
[/code]

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?

Thanks,

Tomas

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 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: http://datatables.net/1.5-beta/examples/data_sources/js_array.html ).

    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?
    Allan
  • tciriptcirip Posts: 9Questions: 0Answers: 0
    Allan,

    You are amazing! Works like a charm.

    Thanks a lot!

    Tomas
This discussion has been closed.