Issue with stateSave option

Issue with stateSave option

anujganujg Posts: 6Questions: 2Answers: 0

I'm having a strange issue when I use "stateSave" option to retain the state of the table. When I use the "stateSave" option, then the page number wording starts showing up as below:

even when the pageLength is set to 50.

If I remove the "saveState" option, then everything works fine.

Not sure if anyone else if having a similar issue but this is strange and I'm not able to use the "saveState" feature.

The code I'm using is below for DataTable:

$(document).ready(function(){
            $("#tblLOI").DataTable({
                "pageLength": 25,
                "stateSave": true,
                "columnDefs": [
                { "orderable": false, "targets": [0, 1, 15] }
              ]
            });
        });

Answers

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,947

    Are you saying that you don't want the pageLength to be save using stateSave?

    If so you can use stateSaveParams to set the page length to 25 each time stateSave runs, for example:

                     "stateSaveParams": function (settings, data) {
                        data.length = 25;
                      },
    

    Kevin

  • anujganujg Posts: 6Questions: 2Answers: 0

    @kthorngren I want to use the "stateSave" feature to save the columns sorting. But what's happening is that the pageLength feature isn't working and also the page entries text shows up as "Showing 1 to 0,100 of 124 entries". See "0,100" instead of 100 here.

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,947

    is that the pageLength feature isn't working

    The pageLength option is, by default, saved during each stateSave. If you don't want this then you can use the above code to always make the pageLength 25. If this is not what you are asking then please explain what "isn't working" means.

    "Showing 1 to 0,100 of 124 entries". See "0,100" instead of 100 here.
    Interesting. Doesn't show that way in this example:
    http://live.datatables.net/rosodawu/1/edit

    Not sure why that would happen on your page. If you disable stateSave and select the pageLength of 100 does it show the same?

    Maybe you can provide a link to your page or a test case replicating the issue so it can be diagnosed. Feel free to update my example.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • anujganujg Posts: 6Questions: 2Answers: 0

    @kthorngren, if I remove/disable the "stateSave" option, then the text shows up correctly. But while trying to work with this issue, I noticed that once I change the page length using the drop down, the text starts showing up correctly. Not sure why it happens in a clean browser session that the text doesn't show up correctly. Anyhow, I have reported this behavior to the Analyst and that's fine with him. Unfortunately I can't post the link to the site but I guess for now this workaround will be okay.

    Thanks for your assistance @kthorngren

  • anujganujg Posts: 6Questions: 2Answers: 0

    @kthorngren I tried putting the below code in the JavaScript section in the live example (http://live.datatables.net/qipuguca/1/edit) :

    $(document).ready( function () {
      var table = $('#example').DataTable({
                    "pageLength": "50",
                    "stateSave": true});
    } );
    

    and I could see the pageLength still defaulted to "100". If I remove the stateSave option, then the pageLength defaults to 50.

    You could try this and see this happening.

  • anujganujg Posts: 6Questions: 2Answers: 0

    @kthorngren well.. that's probably due to stateSave the pageLength is stored in the session. I guess that's not an issue. And I didn't see the "showing 1 to 25 of 57 entries" text displaying incorrectly. So, the stateSave works fine on that live example. Maybe something strange happening on my end.

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,947

    Like I said if you don't want the user selected page length saved then use the above stataeSaveParam config to set the default page length you want. You can try it here:
    http://live.datatables.net/rosodawu/2/edit

    The first time you run it it may not be at 25 but thats because it is getting the previous state save. Going forward it should work.

    Kevin

This discussion has been closed.