Mottie / tablesorter

Github fork of Christian Bach's tablesorter plugin + awesomeness ~
https://mottie.github.io/tablesorter/docs/
2.61k stars 754 forks source link

next sort after a multi-column sort #1482

Open aavmurphy opened 6 years ago

aavmurphy commented 6 years ago

have a table sorted as (columns) +1 +2 +3 then if i click on column 3, i get -3 (instead of +3)

if you click on 1, then fair enough, do a -1 sort but clicking on 2 or 3 should be treated as a (sort on an un-ordered column) , e.g. ascending search by default

Mottie commented 6 years ago

Hi @aavmurphy!

Maybe you're wanting to set the sortRestart option to true?

aavmurphy commented 6 years ago

hi. tried that :) maybe, as the initial sort is "+1 +2 +3", it thinks that col. 3 is already sorted asc., so clicking makes it sort desc.
according to the doco, 'sortrestart' only works on "previously unsorted" cols.

an example https://www.walkingclub.org.uk/walk/ initial sort "+0 +3" click the 'walk' column - you get the idea

Mottie commented 6 years ago

So if I understand correctly, you want to be able to click on the walk column and get it to sort ascending even though it already has an ascending sort (after the region column).

In order to do that you need to reset the sort count within the sort variable (demo):

$(function() {
  $("table").tablesorter({
    theme: "blue",
    sortList: [[0, 0], [3, 0]],
    initialized: function(table) {
      var vars = table.config.sortVars;
      // set sort direction as if it was initially unsorted
      vars[0].count = -1;
      vars[3].count = -1;
    }
  });
});
aavmurphy commented 6 years ago

Yes. Thanks - your solution works! Maybe making the "2nd+" columns (of multi-column sorts) be initialised as "unsorted" could be a new option :)