Skipping pagination in state saving / loading

Skipping pagination in state saving / loading

drewtdrewt Posts: 22Questions: 0Answers: 0
edited November 2013 in General
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

Replies

  • drewtdrewt Posts: 22Questions: 0Answers: 0
    Is the property length of the object null because I'm using server side processing?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi,

    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
  • drewtdrewt Posts: 22Questions: 0Answers: 0
    Ah Ok! I see what you mean.

    Thanks. [code]data.iStart = 0;[/code] is exactly what I needed.
This discussion has been closed.