Column definitions and hidden columns don't work together
Closed this issue · 1 comments
miken32 commented
After upgrading to 2.0 I'm unable to use a column definition on the same table as a hidden column.
new DataTable('#example', {
columns: [
{ data: 'name' },
{ data: 'position' },
{ data: 'office' },
{ data: 'start_date' },
{ data: 'salary' },
{ data: 'id'},
{ data: 'extn', visible: false},
],
ajax: "/ajax/objects.txt",
columnDefs: [
{targets: '.id'}
]
});
<table id="example" class="display nowrap" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Start date</th>
<th>Salary</th>
<th class="id"></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
Live code example is here: https://live.datatables.net/rebozoyu/1/
Commenting out either the hidden column or the column definition will render the table correctly, otherwise an error is thrown. There is a loop over the columns object that assumes the table will have the same number of headers I think? https://github.com/DataTables/DataTablesSrc/blob/master/js/core/core.columns.js#L457
AllanJard commented
Thank you for the test case! Fix committed and it will be in 2.0.2.