Dynamic Columns in DataTables

Dynamic Columns in DataTables

haltmanhaltman Posts: 1Questions: 0Answers: 0
edited April 2011 in General
After much searching I was finally able to get dynamic columns to load correctly.

Here is the magic line of code:
[code]
$('#mc_table').dataTable().fnSettings().nTHead.innerHTML = ''; // This is the line that makes it work.

$('#mc_table').dataTable( {
"bDestroy": true, // This makes the table check for new data every time.
"aaData": _data(),
"aoColumns": _cols(),
"bPaginate": false,
"bJQueryUI": false,
"bLengthChange" : true,
"bFilter": false,
"bSort": true,
"bInfo": false,
"bAutoWidth": false,
"aaSorting": [[3,'desc'],[4,'asc']]
} );
[/code]

This line will remove the current header for the table forcing dataTable to rebuild the header with the new columns in the column object.

I put that line directly in front of my dataTable initializer.

Replies

  • whisperwhisper Posts: 1Questions: 0Answers: 0
    Hey!

    The code is not working. This is the error message I get "DataTables warning (table id = 'example'): Unexpected number of TD elements. Expected 5 and got 1. DataTables does not support rowspan / colspan in the table body, and there must be one cell for each row/column combination."
This discussion has been closed.