javascript – JQuery Datatables : Cannot read property aDataSort of undefined

javascript – JQuery Datatables : Cannot read property aDataSort of undefined

Its important that your THEAD not be empty in table.As dataTable requires you to specify the number of columns of the expected data .
As per your data it should be

<table id=datatable>
    <thead>
        <tr>
            <th>Subscriber ID</th>
            <th>Install Location</th>
            <th>Subscriber Name</th>
            <th>some data</th>
        </tr>
    </thead>
</table>

Also had this issue,
This array was out of range:

order: [1, asc],

javascript – JQuery Datatables : Cannot read property aDataSort of undefined

For me, the bug was in DataTables itself; The code for sorting in DataTables 1.10.9 will not check for bounds; thus if you use something like

order: [[1, asc]]

with an empty table, there is no row idx 1 -> this exception ensures.
This happened as the data for the table was being fetched asynchronously. Initially, on page loading the dataTable gets initialized without data. It should be updated later as soon as the result data is fetched.

My solution:

// add within function _fnStringToCss( s ) in datatables.js
// directly after this line
// srcCol = nestedSort[i][0];

if(srcCol >= aoColumns.length) {
    continue;
}

// this line follows:
// aDataSort = aoColumns[ srcCol ].aDataSort;

Leave a Reply

Your email address will not be published.