JQuery Datatables : Cannot read property 'aDataSort' of undefined

前端 未结 8 1996
日久生厌
日久生厌 2020-12-02 21:43

I created this fiddle to and it works well as per my requirements: Fiddle

However, when I use the same in my application I get an error in the browser console saying

8条回答
  •  旧时难觅i
    2020-12-02 22:13

    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;
    

提交回复
热议问题