I am using Datatables / Editor for almost a year, and am getting fairly comfortable with it, but I still run into issues on occasion.
In this case, I'm trying to initialize the pageLength of a table with a value supplied as a user preference. This is not working correctly. The first page is correct per the setting of the user preference, but clicking any of the numbered page buttons, or 'Next' or 'Previous' displays the entire table, although indicator of what should be displaying is correct. If I change the 'pageLength' using the on-screen selector widget, things behave correctly for that setting and paging then works correctly thereafter, for any setting. It is only when trying to use the 'pageLength' passed in from the user's preferences that it fails.
I retrieve the user preference on the server and embed it in the HTML for the page, and it appears there, correctly. My problem is getting that value into the DataTable definition.
In my javascript that defines the table, I have the following:
lengthChange: true,
'pageLength': function() {
var itPageLen = $('#itPageLen').attr('data-pagelength');
if (itPageLen === 'All') {
itPageLen = -1;
}
},
'lengthMenu': [[10,25,50,100,-1],[10,25,50,100,'All']],
'language': {
'decimal': '.',
'thousands': ','
},
In the HTML, I have the following:
<div id="itRole" data-itRole="tech"></div>
<div id="itPageLen" data-pagelength=All></div>
The program always sets 'data-pagelength' to one of the values in the 'lengthMenu', so there is no mismatch, and no matter which one I use, it always displays the first page correctly and behaves incorrectly in the same way as described above whenever I use any of the paging buttons. I've tried a couple of other ways of initializing 'pageLength', but I always get the same incorrect behavior.
My use of the similar parameter, 'itRole', which affects other behavior , works correctly, which makes this more puzzling.
What is a correct way of passing and using this information?
Thanks in advance,
Tom