Table sorting! This simple plugin lets a user sort a plugin in a nice sort of way. The premise is pretty simple, and so is the plugin. You give it a table and it tries to let you sort it. It assumes the first row is a heading, to which the click events are bound, and anything after that is sortable. Numeric types are coerced into actual numbers so you shouldn't get things like 11 > 100. Two levels of sorting are applied, the second level is the previously selected column.
caseSensitive (default: true) - sets whether or not to use case sensitive string matching (if false strings are converted to lowercase before they are sent to cmp)
cb - An optional callback to fire when the table has completed sorting, this takes one argument which you provide, and has its 'this' set to the table element
cb_data - Your optional callback data.
cmp - Comparsion function which you may choose to override. Works in the usual way, function(a,b) and returns -1, 0 or 1. It also has its 'this' set as the column index that is being sorted
clickerSelector - An optional jQuery selector you can specify to select the clicker elements. This is applied in the context of a heading's td, i.e. $(clickerSelector, $(someheadingtd)). If not specified, the td is used as the clicker.
defaultSort - The default column to sort as soon as the plugin is called on a table (zero indexed).
typeCoecion (default: true) - Whether or not to try to coerce strings into numbers before applying comparison. If you have an unusual number format this might fail, in which case you should override cmp and apply coercion in there.
Simple call, with type coercion. Note that numbers are compared numerically and
units are ignored, and string comparison is case sensitive. The default 'clicker' is the heading.
Note that two levels of sorting are performed, once by the current selection and then again (on elements which are equal) by the last selection.
We can use some CSS wizardry to add in a nice dynamic arrow. We can specify
our own selector to identify the clicker.
In this example we have disabled case sensitive string comparison and disabled type coercion, so
numbers are now compared as strings, which has strange results but may sometimes be preferable. We have also set it so that the first column is sorted by default.