An error mesg when displaying more columns than there are in table [with FIX]
An error mesg when displaying more columns than there are in table [with FIX]

Hello.
I've created a little fix, but stumbled upon that there's no source code on github and I have to put a fix here.
So here it goes:
<table id="ordersTable>
<thead>
<tr>
<th>id</th> <th>requestDate</th>
</tr>
</thead>
</table>
using Ajax with a response with an array of Objects that have more fields and all those fields are setup in request:
$('#ordersTable').DataTable(
{
"ajax" : {
"url": '/api/clients',
"dataSrc": ''
},
columns: [
{ data: 'id' },
{ data: 'requestDate' },
{ data: 'clientId' }
]
});
suddenly we have an error in browser console:
jquery.dataTables.js:5604 Uncaught TypeError: Cannot read property 'style' of undefined
this is because it has 3 visibleColumns but there are 2 headerColumns. So my fix is to be put on line 5597:
if (headerCells.length < visibleColumns.length) {
_fnLog( oSettings, 0, 'Declared visible columns [' + visibleColumns.length + '] > displayed table header cells [' + headerCells.length + ']');
}
Replies
Thanks for this. The DataTables source is here.
However, what you are describing is not actually a bug, but a configuration error. The
columns
array should exactly match the number of HTML columns in the table. Anything else is a configuration error. In this case, if you don't wantclientId
to be shown in the table, just don't include it in the list of column definitions.Allan