Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82031

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

$
0
0

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 + ']');
            }

Viewing all articles
Browse latest Browse all 82031

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>