Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you want the columns to only sort by their initial sort direction, find and comment out this line in jquery.tablesorter.js:</p> <pre><code>this.order = this.count++ % 2; </code></pre> <p>This is the line which updates the column to sort in the opposite direction the next time the header is clicked. Commenting this out means that the sort order will always be the same. But it also means that you won't be able to sort in the opposite direction.</p> <p>I had a situation (which may be the same as you described) where I wanted each column to sort in the initial sort direction the first time I clicked, but still wanted to be able to sort the other direction when I clicked again. eg. Clicking Column A would sort ASC, then clicking again would sort DESC then again ASC. Clicking B would sort ASC, then clicking A again would sort ASC. With the original tablesorter code, that last sort would be DESC, since the Column A sort of the previous click was ASC.</p> <p>Here is how I solved that. It may be kludgy and clumsy, but it works for me.</p> <p>In the buildHeaders function, find this line:</p> <p><code>this.order = formatSortingOrder( checkHeaderOrder(table, index) );</code></p> <p>and add this after it:</p> <p><code>this.initialOrder = formatSortingOrder( checkHeaderOrder(table, index) );</code></p> <p>Replace the line I mentioned earlier:</p> <p><code>this.order = this.count++ % 2;</code></p> <p>With this:</p> <pre><code>if($lastColumn == i){ this.order = ++this.count % 2; }else{ this.order = this.initialOrder; } $lastColumn = i; </code></pre> <p>Now, say Column A's sortInitialOrder was ASC and B was DESC. The following would happen:</p> <ol> <li>Click A: Sorts A ASC </li> <li>Click B: Sorts B DESC</li> <li>Click B: Sorts B ASC</li> <li>Click A: Sorts A ASC</li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload