Skipping pagination in state saving / loading
Skipping pagination in state saving / loading
I'm just wondering what the best method is for always loading the first page of records when refreshing a page if I'm using state saving.
In my table init I tried:
[code]
"fnStateLoadParams": function (oSettings, oData) {
var oTable = $('#vehicletable<?php echo $id;?>').dataTable();
oTable.fnPageChange('first');
},
[/code]
But I receive the following error in the javascript console:
Uncaught TypeError: Cannot read property 'length' of null
In my table init I tried:
[code]
"fnStateLoadParams": function (oSettings, oData) {
var oTable = $('#vehicletable<?php echo $id;?>').dataTable();
oTable.fnPageChange('first');
},
[/code]
But I receive the following error in the javascript console:
Uncaught TypeError: Cannot read property 'length' of null
This discussion has been closed.
Replies
The above won't work because fnStateLoadParams is called during the initialisation of DataTables, while fnPageChange expects the table to be fully initialised before being used.
To ensure that the first page is always loaded you could use:
[code]
"fnStateLoadParams": function (settings, data) {
data.iStart = 0;
},
[/code]
The properties of what are state saved aren't well documented I'm afraid. Indeed i had to look that up in the code there... They are available here: https://github.com/DataTables/DataTables/blob/1_9/media/js/jquery.dataTables.js#L4446 . That's something I need to fix!
Regards,
Allan
Thanks. [code]data.iStart = 0;[/code] is exactly what I needed.