tablesorter icon indicating copy to clipboard operation
tablesorter copied to clipboard

Using saveSort and initialSort together results in uncorrect behaviour

Open matjaz321 opened this issue 4 years ago • 1 comments

Hey, So I noticed that if you use saveSort and initialSort together it doesn't work correctly.

Steps to reproduce:

  1. Use the following config
tableSorterConfig = {
            forceLoad: true,
            widgets: ['uitheme', 'saveSort'],
            widgetOptions: {
                saveSort: true,
            },
            sortList: [[2,1]],
        }
  1. Go to the page and sort by any other columns except [2, 1]
  2. Refresh the page
  3. Table is sorted correctly by the column you previously sorted by
  4. Refresh the page
  5. Table was sorted by the initialSort

Expected behaviour should be when you refresh the page for the 2nd time it should still be sorted by the sort settings saved in localStorage.

matjaz321 avatar May 28 '20 11:05 matjaz321

Hi @matjaz321!

Hmm, that is strange.

When I test it in this demo - https://jsfiddle.net/Mottie/bbxxomhx/2031/ - I see the saved sort is restored every time, but only if I use the "Run" button at the top. If I reload the page completely, it uses the sortList, and the saved sort isn't found in local storage. I think it may be a quirk of JSFiddle since the storage values are there when I look, but not initially? No idea.

When I create the same demo locally, it consistently restores the saved sort.

So, I guess I can only think of recommending that these two things are checked:

  • Make sure the storage widget has been loaded. It's included in the jquery.tablesorter.widgets.js file, but you'll need to include it if you use saveSort from outside of that file.

  • Check to make sure the storage is being saved; Open up the dev tools and look in the application tab > local storage

    2020-05-28 07_44_26-Slack _ random _ Ad Hoc

Mottie avatar May 28 '20 12:05 Mottie