This is an example of how one might do sortable tables in an
inobtrusive manner. The data is supplied by the server and is
already in the table.
On page load, the SortableManager:
-
Finds the table by its id (sortable_table).
-
Parses its thead for columns with a "mochi:format"
attribute.
-
Parses the data out of the tbody based upon
information given in the "mochi:format" attribute,
and clones the tr elements for later re-use.
-
Clones the column header th elements for use as a
template when drawing sort arrow columns.
-
Stores away a reference to the tbody, as it will be
replaced on each sort.
-
Performs the first sort.
On sort request:
-
Sorts the data based on the given key and direction
-
Creates a new tbody from the rows in the new ordering
-
Replaces the column header th elements with clickable
versions, adding an indicator (↑↓) to the
most recently sorted column.