Using bStateSave with iDeferLoading...

Using bStateSave with iDeferLoading...

ravishbhagdevravishbhagdev Posts: 4Questions: 0Answers: 0
edited November 2012 in General
Hi,

I'm trying to get bStateSave working with my table as I want to maintain the sort order for the user when page is refreshed or when user comes back to a page with the table.

According to http://datatables.net/examples/basic_init/state_save.html just adding "bStateSave": true should be enough? But this is not working for me (version 1.9.3). I was wondering if this is because I use iDeferLoading? If yes, how do I get it work if I need to keep iDeferLoading as well? I am only guessing that it is not working because of iDeferLoading so please correct me if wrong.

[code] tbl = $(selector).dataTable({
"bStateSave": true,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": dataSource,
"iDeferLoading": totalRecCount,

"sDom": layout ? layout : defaultLayout,
"fnDrawCallback": drawCallback,
"aoColumns": aoColumns,
"oLanguage": {
"sSearch": ""
}
});
[/code]

Thanks for a great library btw!
Rav

Replies

  • allanallan Posts: 63,052Questions: 1Answers: 10,382 Site admin
    Deferred loading and state saving are mutually exclusive - the two cannot exist together. I should perhaps put a check into the code to disable deferred loaded when state saving is enabled.

    The reason they won't work together is that deferred loading means that the data from the HTML table is read for the first draw and shown, loading only on sort, filter, page - but that data in the HTML is unlikely to be the data for the saved state - hence why it is broken.

    Note made to disable deferred loading in this situation :-)

    Allan
  • ravishbhagdevravishbhagdev Posts: 4Questions: 0Answers: 0
    Understood. Makes sense. I guess I'll have to implement a custom cookie that gets read and used for sending the first page according to the saved state.

    Thanks Allan.
  • ravishbhagdevravishbhagdev Posts: 4Questions: 0Answers: 0
    Wondering where will be best place to save the cookie though. Because I need to capture the exact sort event to overwrite it. Controller just gets the current parameters and uses them and there will be no way of telling if the sort was performed for the request or if its a normal default request. (Looking into call backs)
This discussion has been closed.