fnStateSave, with bServerSide and fnServerData

fnStateSave, with bServerSide and fnServerData

jdegejdege Posts: 4Questions: 2Answers: 0
edited December 2013 in DataTables 1.9
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?

Replies

  • Dooks123Dooks123 Posts: 4Questions: 0Answers: 0
    stop reinventing the wheel

    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
  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    edited December 2013
    I've got a funny feeling that this might be a bug in 1.9.4. I can't remember, and can't see where it was fixed if it was, but could you try your table with the DataTables 1.10-dev version please: http://datatables.net/download ? If that doesn't work, can you link me to the page so I can inspect what is happening, as the state saving should be restoring you (your table!) to the previous state.

    Allan
  • jdegejdege Posts: 4Questions: 2Answers: 0
    Tried it with 12/10's 1.10-dev. made a few adjustments:

    * 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.
This discussion has been closed.