PageLength and SaveState correlation

PageLength and SaveState correlation

MadBoyEvoMadBoyEvo Posts: 119Questions: 38Answers: 0

Link to test case:
It seems that when SaveState is enabled, changing PageLength once it loads is impacted. For example, I'm doing some verifications on an example I set page length to 5 with savestate set to true. Later on, I change it to 15 and I can't see things changing as Savestate prevents the change to show.

https://codepen.io/MadBoyEvo/pen/gOMYeeE

Is this by design or could this be somehow workaround? This seems to "live" for a long time, browser closing and so on.

Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770
    edited October 2020

    I might be misunderstanding the problem but the tables in your example have only 4 rows. Changing to 15 rows won't change anything with the table display. I made the following chages to one of your tables and can change the page length:

                           "lengthMenu": [
                                [
                                    1,
                                  2,
                                  3,
                                  4,
                                  15,
                                    25,
                                    50,
                                    100,
                                    -1
                                ],
                                [
                                    1,
                                  2,
                                  3,
                                  4,
                                  15,
                                    25,
                                    50,
                                    100,
                                    "All"
                                ]
                            ],
    

    But I can only change it from 1 to 4. Can't save the changes as I don't have a codepen account.

    Kevin

  • MadBoyEvoMadBoyEvo Posts: 119Questions: 38Answers: 0

    It's just minified example. Length menu doesn't matter. PageLength does. If you play with the file locally (save as .HTML) and change from 5 to 1 and save, change then save and refresh. Nothing happens when save state is on.

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    Still not seeing the problem. I copied your code here:
    http://live.datatables.net/lupugila/1/edit

    I added 2 to the lengthMenu of the first table. And changed "stateSave": false, to "stateSave": true, in the second table.

    I can change the page length using the button reload the page and it shows the page length I changed to. In the first table I can set it to a page length of 2 and go to page 2. Reload the page and it shows a page length of 2 and the table displays page 2.

    change from 5 to 1 and save, change then save and refresh

    Sorry, I'm not clear how you are doing this. I still may not understand the issue you are asking about.

    See this example:
    http://live.datatables.net/lupugila/1/edit

    Kevin

  • MadBoyEvoMadBoyEvo Posts: 119Questions: 38Answers: 0

    Again - not lengthMenu, pageLength. Leave LengthMenu alone. It doesn't matter.

                     "pageLength": 2,
                     "stateSave": true,
    

    Change 2 to 4. Save and refresh. Change it to 3, refresh. Notice how it will always show whatever you had first.

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770
    Answer ✓

    Sorry, too early in the morning I guess :smile:

    If you don't want to save the pageLength then use the stateSaveParams to set the page length to what you want. Like this, see the first table:
    http://live.datatables.net/lupugila/3/edit

    Kevin

  • MadBoyEvoMadBoyEvo Posts: 119Questions: 38Answers: 0

    Great. Thank you!

This discussion has been closed.