JQuery Datatables : Cannot read property 'aDataSort' of undefined

前端 未结 8 1979
日久生厌
日久生厌 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条回答
  •  暖寄归人
    2020-12-02 22:18

    I had this problem and it was because another script was deleting all of the tables and recreating them, but my table wasn't being recreated. I spent ages on this issue before I noticed that my table wasn't even visible on the page. Can you see your table before you initialize DataTables?

    Essentially, the other script was doing:

    let tables = $("table");
    for (let i = 0; i < tables.length; i++) {
      const table = tables[i];
      if ($.fn.DataTable.isDataTable(table)) {
        $(table).DataTable().destroy(remove);
        $(table).empty();
      }
    }
    

    And it should have been doing:

    let tables = $("table.some-class-only");
    ... the rest ...
    

提交回复
热议问题