jQuery tablesorter secondary sorting problem
While switching a table sort script over to the excellent new jQuery Tablesorter 2.0, I came across an implementation that, to me, didn’t seem right.
In the configuration options, you can set a forceSort column, which—according to the documentation—will “add an additional forced sort that will be appended to the dynamic selections by the user”. What it actually seems to do, though, is apply the forced columns before the one you clicked on, meaning that you can’t actually sort by anything apart from the forceSort column(s).
To fix this behaviour, simply move this block of code:
if(config.sortForce != null) {
var a = config.sortForce;
for(var j=0; j < a.length; j++) {
config.sortList.push(a[j]);
}
}
So that it appears after this line:
config.sortList.push([i,this.order]);
Now the user sort is applied before the forced sort column(s), and everything works as intended.
Filed under: Javascript.
Technorati tags: jquery tablesorter javascript
Bookmark this article with del.icio.us
Previously: Process
Next: Neutral Milk Hotel: In The Aeroplane Over The Sea