Save pagination with cookies

Save pagination with cookies

WebDevWebDev Posts: 21Questions: 0Answers: 0
edited November 2012 in DataTables 1.9
I am trying to set up a scenario where a user can go to some page on a DataTable after page 1 and when they then go to a new page and the same DataTable appears it will remember what page they had been on before. Setting "bStateSave" to "true" doesn't seem to do that. I am using the jQuery cookie plugin for some other things on this project so perhaps somebody knows a way for me to combine the two?

I'll try to post an example at DataTables Live if anyone deems it necessary but the code on this project is all over the place in many different files.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    It should do, as you can see in this example: http://datatables.net/release-datatables/examples/basic_init/state_save.html .

    Allan
  • WebDevWebDev Posts: 21Questions: 0Answers: 0
    edited November 2012
    Okay, it works somewhat. Let me explain better what my project is like and what is happening. On the left there is a table (that the DataTables plugin is applied to) that has a number of choices in it. In our current working example there are 23 choices so that the DataTables plugin splits those into three pages. If you select any of those 23 choices it takes you to a details page for that particular choice, but when you go to that page we need the DataTable on the left to show the page you had made the selection from. So, if you select Choice #14 then you go to the Choice #14 details page and hopefully the DataTables plugin on that page will show up with page 2 appearing. Okay, now the weird thing is that the only time that works is when Choice #11 is selected. If you pick any other choice from 1-10 and 12-23 then it goes to the details page for that choice but shows Page #1 of the DataTable (of course that makes sense for 1-10 but not for anything else). Why would it only work on that one choice?

    UPDATE: It seems to work sporadically off an on for different elements. Since it does work some of the time I'm not sure how to change the code to make it work all the time.
  • WebDevWebDev Posts: 21Questions: 0Answers: 0
    Still wondering if there's an answer...
  • WebDevWebDev Posts: 21Questions: 0Answers: 0
    Maybe somebody could at least point out which part of the cookie controls pagination, because i am not readily seeing it in here:

    {"iCreate":1353958066655,"iStart":0,"iEnd":10,"iLength":10,"aaSorting":[[1,"desc",1]],"oSearch":{"bCaseInsensitive":true,"sSearch":"","bRegex":false,"bSmart":true},"aoSearchCols":[{"bCaseInsensitive":true,"sSearch":"","bRegex":false,"bSmart":true},{"bCaseInsensitive":true,"sSearch":"","bRegex":false,"bSmart":true},{"bCaseInsensitive":true,"sSearch":"","bRegex":false,"bSmart":true},{"bCaseInsensitive":true,"sSearch":"","bRegex":false,"bSmart":true}],"abVisCols":[true,true,true,true]}
  • WebDevWebDev Posts: 21Questions: 0Answers: 0
    Here's a live example I'm working on:

    http://live.datatables.net/uqacix

    When any option beyond 10 is picked it goes to the details page for that option but we need the DataTable on the new page to show the page the selected option had been selected from.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    > Maybe somebody could at least point out which part of the cookie controls pagination

    It is iStart:

    > "iStart":0

    Thank you for the test case although it doesn't actually appear to do anything for me? Clicking around it doesn't do anything.

    One key thing here is that Cookies are limited to for 4KiB and DataTables will remove cookies that go over that limit (otherwise you'd get a server error). It might be that you'd be best switching to use localStorage rather than cookies: http://datatables.net/blog/localStorage_for_state_saving - DataTables 1.10 will do localStorage by default.

    But beyond that we'd need a working test case showing the issue I think.

    Allan
  • WebDevWebDev Posts: 21Questions: 0Answers: 0
    Yeah, the project hasn't gone live yet so there's no way to post a working link and the example I created here would never be able to show all of the functionality. But now that you've pointed out "iStart" I have gone back to my page on the local server and the value of every instance of "iStart" is set to 10.
This discussion has been closed.