Mottie/tablesorter

Impossible to differentiate between "appened" sorts and user-initiated sorts

GHLover opened this issue · 3 comments

The Goal
It often makes sense to control the sort of a grid when the user-selected sort produces values of the same sort value. For example, imagine a table listing Country, State, and GDP. If a user selected to sort by Country, it would produce a grid with a sort that matched many rows based on Country, so within a particular country it is not being usefully sorted as it is sorted at random.

So, to help the user out, appendSort is used to sort by GDP as a secondary attribute. This is merely a convenience for the user.

The Problem

Currently, appendSort are treated as if they are user-inititated. This means that "tablesorter-header[Asc/Desc]" are added to the column. As a result, due to formatting, it makes the user beleive THEY selected to sort by State when in fact they did not. It is very confusing situation because the appendSort is in the background done just as a convenience for the user.

Solution?

It would be good if any sorts that were done as a result of appendSort or non-user action gets another css class so it can be differentiated. For example, tablesorter-headerAppendSorted. This way we can choose to highlight or not highlight this column. It is 100% backwards compatible with current behavior so will not cause undo issus for people who upgrade. And, it gives people who do not want the user to know sorting is being done in the background on their behalf a way to hide it.

Hi @GHLover!

That sounds like a reasonable request. I'll add it to my to-do list.

Updated in the master branch...

So instead of adding more class names, I instead added a data-attribute of data-sortedBy:

The value can be:

  • 'user' (renamed from 'mouseup' event) when a column is sorted by a user.
  • 'sort' when a column is sorted by triggering a sort event on the header.
  • 'sorton' when a column is sorted using the sorton method.
  • 'sortAppend' when a sorted column is added by the sortAppend option.
  • 'sortForce' when a sorted column is added by the sortForce option.

There may be other values that I can't think of right now because the value is set from the event.type; but not the 'sortAppend' and 'sortForce' values.

This is now available in v2.30.7 - see the docs for config.sortVars.