fnStateSave, with bServerSide and fnServerData
fnStateSave, with bServerSide and fnServerData
jdege
Posts: 4Questions: 2Answers: 0
First, the DataTables debugger gave me: aqolan
I have a page that is pulling data from an ASP.NET MVC controller, by over-riding fnServerData:
[code]
"bServerSide": true,
"fnServerData": function(sSource, aoData, fnCallback, oSettings)
{
saveSearchElements(aoData);
oSettings.jqXHR = $.ajax({
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
});
},
[/code]
The function saveSearchElements() pushes values from some criteria elements on the page into the aoData array.
My controller action gets passed my criteria data and iDisplayLength and iDisplayStart. I include these in my Entity Framework query, using Skip() and Take(). The result is that my controller action only returns a single datatable page worth of data. When I select a new page, or a new page size, in the datatable, fnServerData() calls my controller action with the appropriate iDisplayLength and iDisplayStart.
So here's the problem - if I navigate away from the page that contains the datatable and then navigate back, I want to see the same data in the grid - on the same page. And that's not happening.
I'm saving my criteria data in sessionStorage, and that's working fine. And I'm trying to use fnStateSave() and fnStateLoad(), to save the datatable parameters in sessionStorage, and that's not.
I can see, in the debugger, oData.iStart being restored from sessionStorage, but in fnServerData(), aoData always contains { name: iDisplayStart, value: 0}.
Either there's a bug in datatables, or I'm simply not understanding how things are supposed to work.
My guess would be the latter.
Any ideas as to how to get perserve paging data, using server-side Ajax?
I have a page that is pulling data from an ASP.NET MVC controller, by over-riding fnServerData:
[code]
"bServerSide": true,
"fnServerData": function(sSource, aoData, fnCallback, oSettings)
{
saveSearchElements(aoData);
oSettings.jqXHR = $.ajax({
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
});
},
[/code]
The function saveSearchElements() pushes values from some criteria elements on the page into the aoData array.
My controller action gets passed my criteria data and iDisplayLength and iDisplayStart. I include these in my Entity Framework query, using Skip() and Take(). The result is that my controller action only returns a single datatable page worth of data. When I select a new page, or a new page size, in the datatable, fnServerData() calls my controller action with the appropriate iDisplayLength and iDisplayStart.
So here's the problem - if I navigate away from the page that contains the datatable and then navigate back, I want to see the same data in the grid - on the same page. And that's not happening.
I'm saving my criteria data in sessionStorage, and that's working fine. And I'm trying to use fnStateSave() and fnStateLoad(), to save the datatable parameters in sessionStorage, and that's not.
I can see, in the debugger, oData.iStart being restored from sessionStorage, but in fnServerData(), aoData always contains { name: iDisplayStart, value: 0}.
Either there's a bug in datatables, or I'm simply not understanding how things are supposed to work.
My guess would be the latter.
Any ideas as to how to get perserve paging data, using server-side Ajax?
This discussion has been closed.
Replies
Sources:
- http://weblogs.asp.net/zowens/archive/2010/01/19/jquery-datatables-plugin-meets-c.aspx
- http://activeengine.net/2011/02/09/datatablepager-now-has-multi-column-sort-capability-for-datatables-net/
- http://rantdriven.com/post/Using-Datatablesnet-JQuery-Plug-in-with-WCF-Services.aspx
Allan
* aoData is an object, instead of an array of name/value pairs
* fnStateSave and fnStateLoad are now fnStateSaveParams and fnStateLoadParams
Gave it a try, and got the same behavior.
When I load the page, fnStateLoadParams is called, and oData is retrieved from sessionStorage, and iStart has the proper value. But fnServerData() is not called, and so no call is made to the server to retrieve data to populate the grid.
And if I call fnDraw() myself, it results in fnServerData() being called with iDisplayStart=0 - which makes sense, if fnDraw() is meant to load new data into the table. But I don't see any mechanism to tell the table to reload the data it had, before.