If you have an error 'Uncaught TypeError: Cannot read property 'nTr' of ...', this might fix it

If you have an error 'Uncaught TypeError: Cannot read property 'nTr' of ...', this might fix it

aukeauke Posts: 1Questions: 0Answers: 0

I ran into this problem and traced it back to the stateSave and Load callback. The save posts form entries to a php backend. This backend stores it and the load callback retrieves it, but turns it into json. However, the PHP backend automatically saves everything as a string, so the start and length state properties came back in the json as :

"start": "0",
"length": "10"

the paging then said "01 to 010 of 98 results" and pressing 'next' triggered the error above, clicking on page 2 showed all results from 11 to 98.

The solution is to either fix the php save to store numbers as ints, or to fix in javascript in the load callback.

Ideally this should be fixed in the datatables code, in _fnLoadState,:

if ( s.start !== undefined ) {
settings._iDisplayStart = parseInt(s.start);
settings.iInitDisplayStart = parseInt(s.start);
}
if ( s.length !== undefined ) {
settings._iDisplayLength = parseInt(s.length);
}

I've posted this here for anyone running into the same issue.

Auke van Slooten
Muze.nl

This discussion has been closed.