How to save the state of server-side queries

How to save the state of server-side queries

GreggBGreggB Posts: 4Questions: 0Answers: 0
edited May 2011 in General
It's quite possible that I'm misunderstanding the purpose of the bStateSave option, so please bear with me.

Basically, I have a web page with a search form and an empty HTML table. If the user performs a search, I'm making an Ajax call to the web server, processing the results and populating the HTML table. For the time being, I've disabled both sorting and filtering of the table. Sorting will be enabled at a later date and filtering is done via the search form. Paging, however, is enabled. As part of the rendering of data received from the server, I'm creating a "View details" link in one of the columns. So the HTML table shows a high-level view of the data, but users can click the "View Details" link of any row to visit the Details page (i.e., the URL is something along the lines of "/Details?=101", etc.)

The problem I have is that once users click a link to go to the Details page and then use their browser's Back button, the HTML table on the Search page is empty again. In other words, they have to re-enter their search query (and possibly navigate to the appropriate page of results).

Is this something that '"bStateSave": true' should resolve? Because it doesn't seem to be working although perhaps I've got some code elsewhere that's overriding the saved state. Any constructive suggestions would be greatly appreciated. Thanks!

Replies

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin
    You are quite correct in your assumption of what bStateSave should do - an example of that in action can be seen here: http://datatables.net/examples/basic_init/state_save.html (hit page forward and then reload the page).

    I think there might have been a bug in DataTables which you are encountering at the moment. Could you try your test with the 1.8 beta release please and see if that addresses it (certainly in the commit notes there is a bug related to this that I fixed).

    Regards,
    Allan
  • GreggBGreggB Posts: 4Questions: 0Answers: 0
    edited May 2011
    Thanks, Allan. I've downloaded the current 1.8 beta and ran the page...looks like you made some changes to how fnRender works as

    [code] {
    "fnRender": function (oObj) {
    return '' + oObj.aData[0] + '';
    },
    "aTargets": [0], "bSearchable": false
    },[/code]

    ...seems to produce the following HTML...

    [code]1000548[/code]

    Once I've had a chance to tweak the code and test the state saving code, I'll update this thread.

    Thanks!
    - g
  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin
    Sorry about that. fnRender is currently called twice when using it with server-side processing. This is for reasons of the new internal data processing - and in retrospect is probably wrong - I'm just not 100% sure how to address it at the moment... I'll be looking at addressing this for the next beta. However in the mean time, the work around is to have bUseRendered ( http://datatables.net/usage/columns#bUseRendered ) set to false for the column with fnRender on it.

    Allan
  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin
    Actually - just worked out how to deal with this situation :-). I've just committed a patch - you can get the very latest version from the "nightly" on the downloads page: http://datatables.net/download/ - it should allow your fnRender code to work exactly the same way as 1.7.x.

    Regards,
    Allan
  • GreggBGreggB Posts: 4Questions: 0Answers: 0
    Thanks, allan...using the "bUseRendered" option set to false seems to have done the trick. I'll check out that new patch, though.

    As for the state of the grid, that seems to be lost when users hit the back button. I need to review my code to see if there's something that's causing the table to "reset" back to its original, blank state. I'll try to remember to post back here one way or the other in case it's helpful for others, too.

    Thanks again for your help!
    - g
  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin
    If you can give me a link ( http://datatables.net/contact if you don't want to make it public) I can take a look and see what might be causing the issue.

    Allan
This discussion has been closed.