I ran into a situation today where I had to sort Social Security Numbers (yes, I know, storing SSNs is a no-no) in a table. I use the wonderful Jquery Tablesorter plugin by Christian Bach and it works beautifully, generally.
The problem arose, because in the presentation of the SSNs in the table, they are formatted like most Americans expect, 123-45-6789. However, when the tablesorter started doing the sorting, it actually performed the arithmetic on the field and sorted the result, rather than the string. I post this because, admittedly, it took me quite a while to figure out how the sort was behaving, and maybe this will save someone else some time.
So, I tried to add the custom parser. Following these the tablesorter docs and a blog post by Ori Peleg. I got this to work, sorta. I stripped out the dashes, making the SSNs just numbers and it would sort. But only one direction. Meaning they’d come in random and I could use the tablesorter to sort them descending, but clicking the header again would not sort ascending. Furthermore, it broke the rest of the sorters. I am sure this is all in the way I coded, but I never got it to work through jquery.
I ended up using PHP to replace the dashes with spaces and they sort fine using the default tablesorter sorting.
