bStateSave issues if multiple dataTables are using from the same URL

bStateSave issues if multiple dataTables are using from the same URL

GaryFGaryF Posts: 16Questions: 0Answers: 0
edited April 2009 in General
I've used bStateSave:true which nicely returns users to the correct paged records if they go off and come back later. However, I'm using dataTables to present data on different record sets using a URL parameter to specificy the data set to use, but the cookie only records the page/script name and not the URL parameters. So it applies the last saved state to every data set, even the wrong ones. Let me give a simplified example.

users.php?country=england

This page shows all users from England in the dataTable. (Other stuff on the page is specifically about England, so the url param is important to server-side code on the page.) Let's pretend I've paged on to the 3rd page of the dataTables results. Now I navigate to...

users.php?country=usa

It now shows users from the USA but it has started on the 3rd page, not the first.

I understand why DataTables does this but I was wondering if there's a solution. It would be over the top to store a cookie for every different URL parameter because there would be 100's of cookies created. (My app isn't about countries but there are 1000's of "countries" that it uses, if you see what I mean, I just needed to use a plain example so I don't have to bore you with what my app is about!)

Thanks!

Replies

  • GaryFGaryF Posts: 16Questions: 0Answers: 0
    Allan, I've figured out a solution but it needs a new feature in the plugin! What do you think of this...

    Add a new option called bStateKeyword which, using server side scripting, tells DataTables what data set you're using on the current page. e.g.
    bStateKeyword : england

    Then the cookie can be set to additionally store "england".

    Now when you visit users.php?country=usa the DataTables options will have bStateKeyword : usa and the logic would be:

    if (bStateKeyword == the last keyword stored in the cookie) {
    Use the state stored in the cookie
    } else {
    Don't use the stored state, but update the same cookie with the new bStateKeyword
    }

    This would be really useful for users returning to the same data table, especially if they can click on a row to go to a master detail editing page and then need to go back to the data table again. But if they go to a different data table (same URL with different params to get a different data set) then the state will be reset - which is perfect.

    It's just an idea and I appreciate only ideas that you think would benefit a lot of people stand a chance of making it into a future release. But if no one asks... ;-)
  • allanallan Posts: 63,578Questions: 1Answers: 10,483 Site admin
    Hi Gary,

    Just a quick thought (more later when I can think about it!) - you might be able to alter the 'oSettings.sInstance' parameter to suit your needs. DataTables uses this (along with the path) to create the cookie name (and very little else) - so adding your query onto that might do the trick...

    Allan
This discussion has been closed.