I am using this wonderful version of jQuery Tablesorter: http://mottie.github.com/tablesorter/docs/index.html
Everything works well, but now I have this problem: I have one column in the table that contains the positions of the basketball players. Therefore, I want this column to be sorted logically as follows: PG-SG-SF-PF-C.
I tried to create this custom sorting function - look at my script, column 2:
$(document).ready(function() { $(".stats").tablesorter({ sortInitialOrder: 'desc', sortRestart: true, // Enable use of the characterEquivalents reference sortLocaleCompare: false, // if false, upper case sorts BEFORE lower case ignoreCase: true, headers: { 0: { sortInitialOrder: 'asc' }, 1: { sortInitialOrder: 'asc' }, 2: { textSorter: function(a, b){ var positions = { "PG": 0, "SG": 10, "SF": 20, "PF": 30, "C": 40 }; return ((positions[a] < positions[b]) ? -1 : ((positions[a] > positions[b]) ? 1 : 0)); }, sortInitialOrder: 'asc' } } } ); });
However, the column is still sorted alphabetically as a regular text string (C-PF-PG-SF-SG).
Where am I making a mistake? I am not particularly strong in Javascript, so it is probably located somewhere in the sort function. Thanks.
source share