Web Development with jQuery®

(Elliott) #1

(^440) ❘ CHAPTER 19 TABLESORTER
$('table').tablesorter({
sortMultiSortKey : 'altKey'
});
You can also change the class names applied to the elements using the options cssHeader,
cssAsc, and cssDesc. The default value of cssHeader is header. The default value of cssAsc is header-
SortUp, and the default value of cssDesc is headerSortDown.
$('table').tablesorter({
sortMultiSortKey : 'altKey',
cssHeader : 'tableSorterHeader',
cssAsc : 'tableSorterAscending',
cssDesc : 'tableSorterDescending'
});
Finally, if your table contains additional markup in the table cells, you need to account for the
markup using the textExtraction option. The textExtraction option can be the string 'simple' or it
can be a callback function. Whatever method you use, it should be as fast and as optimized as pos-
sible. The method provided would be slow because it uses jQuery and the numerous chains of func-
tion calls that entails.
$('table').tablesorter({
sortMultiSortKey : 'altKey',
cssHeader : 'tableSorterHeader',
cssAsc : 'tableSorterAscending',
cssDesc : 'tableSorterDescending',
textExtraction : function(node)
{
return $(node).text();
}
});
The initial sorting of a table is controlled with the sortList option. This options allows you to
provide an array that describes how a table should be sorted after the $.tablesorter() plugin has
been applied. The default behavior is to not change the sorting of the table until the user explicitly
clicks a header to sort a column. The following example sorts the table by default, the same way
it is sorted in Figure 19-2, which is to say, it is fi rst sorted ascending by Album and then sorted
ascending by Name.
$('table').tablesorter({
sortList : [
[2, 0],
[1, 0]
]
});
Each column is referenced by number, offset from zero. The fi rst column sorted is the third column.
Then you specify ascending or descending by specifying 0 for ascending and 1 for descending. So,
[2, 0] sorts the third column ascending, and [1, 0] sorts the second column ascending after that.
Additional options for customizing a $.tablesorter() plugin implementation are available in
Appendix T.
http://www.it-ebooks.info

Free download pdf