How do you add columns after initialisation?

How do you add columns after initialisation?

world123world123 Posts: 4Questions: 0Answers: 0
edited August 2011 in General
I would like to use DataTables for displaying server data. The data has a dynamic number of columns.
How do you add columns after initialisation?

or do I have to recreate the table?

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    You don't - currently there is no way to dynamically add or remove columns in a DataTable I'm afraid. I'm sure a plug-in could be created which does it (and that is on my to-do list - just not yet had a chance to do it yet!). Until then you need to destroy and recreate the table.

    Allan
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    If you anticipate adding columns, another approach you could take would be to add the several columns at init time and hide them. Then display them and add content to them as you "add" them later in your app.

    This is not as flexible as dynamically adding columns, but might be a reasonable workaround for now.
  • world123world123 Posts: 4Questions: 0Answers: 0
    To destroy and to recreate the table is working for me. I am using the fnDestroy() function.

    [code]
    $('#myTable').dataTable().fnDestroy();
    [/code]

    Thanks
This discussion has been closed.