Error when using language URL and table.columns.adjust().draw();

Error when using language URL and table.columns.adjust().draw();

tomaytomay Posts: 2Questions: 1Answers: 0

Link to test case: https://jsfiddle.net/xkmnf7p4/
Error messages shown: "jQuery.Deferred exception: headerCells[i] is undefined", "_fnCalculateColumnWidths@https://cdn.datatables.net/1.10.24/js/jquery.dataTables.js:5647:5
_fnAdjustColumnSizing@https://cdn.datatables.net/1.10.24/js/jquery.dataTables.js:2174:28
https://cdn.datatables.net/1.10.24/js/jquery.dataTables.js:8744:25
iterator@https://cdn.datatables.net/1.10.24/js/jquery.dataTables.js:7073:15
https://cdn.datatables.net/1.10.24/js/jquery.dataTables.js:8743:15
https://cdn.datatables.net/1.10.24/js/jquery.dataTables.js:7240:19
https://fiddle.jshell.net/_display/?editor_console=true:148:17
e@https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js:2:30005
https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js:2:30307
", undefined
Description of problem: When including a URL to a language plug-in, and then calling table.columns.adjust().draw(), the above error is thrown. As seen in the above Fiddle, if you comment out the language URL, then table.columns.adjust().draw() completes without issue

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974
    Answer ✓

    When including a URL to a language plug-in

    This is an asynchronous process. The table.columns.adjust().draw() is executed before the Datatable is initialized. Place it within initComplete, like this:
    https://jsfiddle.net/rp49tbo5/

    Kevin

  • tomaytomay Posts: 2Questions: 1Answers: 0

    That was it! Thank you so much

This discussion has been closed.