Notes

  • Added v2.22.4. Instead of using the saveSort widget, this widget updates the hash tag to allow saving & sharing a sort applied to a tablesorter table.
  • Sort the tables in the demo below. Notice the changes made to the location hash, then reload the page to have the hash applied to the tables.
  • This widget requires jQuery version 1.7+.
  • This widget does NOT work with tablesorter v2.0.5.

Options

Sort2Hash widget default options (added inside of tablesorter widgetOptions)

TIP! Click on the link in the option column to reveal full details (or toggle|show|hide all) or double click to update the browser location.
OptionDefaultDescription
sort2hash_hash '#' The hash should always be there. This option was added to allow setting extra hash parameters and/or hashbang or whatever.
',' Change the hash separator using this option. There are some limitations.

In the location hash, the sort parameters are added as &tableID=column,direction, ... ,column,direction (no spaces). This option allows changing the column-direction separator, a comma by default, into the chosen separator.

*NOTE* Do not set this option to use a hash (#), ampersand (&) or equal sign (=) as it will interfere with how the hash parameters are set up.

null Set an ID here to override the table id attribute.

In the location hash, the sort parameters are added as &tableID=column,direction, ... ,column,direction (no spaces). The tableID is set by this option.

This option setting is prioritized over the actual table ID attribute. If neither are set, the tableID will be set as the table's zero-based index on the page.

sort2Hash_tableID > table.id attribute > table index
false If true, text from the header is used instead of a zero-based column index.

Please be aware that if the column text contains spaces or special characters, they will be encoded in the URL. So, "First £$€¤¥¢ Name" will become "First%20%C2%A3$%E2%82%AC%C2%A4%C2%A5%C2%A2%20Name". This would make the hash very difficult to read.

Further processing of this header cell text can be done using the sort2Hash_processHeaderText function.

null If the sort2Hash_useHeaderText option is true, a function here will further process the header cell text.

Use this function to perform any processing on the header cell text, as desired.

At this point, the header cell text has not been encoded.

Here is one example:

sort2Hash_processHeaderText : function( text, config, columnIndex ) {
  // remove all non-alphanumeric characters (including spaces)
  return text.replace( /[^a-z0-9]/gi, '' );
}
Another example:
sort2Hash_processHeaderText : function( text, config, columnIndex ) {
  // completely custom text to use for the hash
  // this method assumes that the table layout is constant
  // (i.e. columns are not added, removed or rearranged)
  return [ 'first', 'last', 'age', 'total', 'disc', 'date' ][ columnIndex ];
}
[ 0, 1 ] Set the direction text shown in the URL.

Only the first two values will be used from this array. The first value is assigned to ascending sorts and the second is assigned to descending sorts.

Use the option as follows:

sort2Hash_directionText : [ 'asc', 'desc' ]
*NOTE* When converting the hash into a value, if the direction hash does not match the second value ('desc' in the example above), it will fallback to an ascending sort no matter what text in contained within the first value.
sort2Hash_overrideSaveSort false if true, the hash sort will override any stored sort (saveSort widget).

Demo

First Name Last Name Age Total Discount Date
PeterParker28$9.9920%Jul 6, 2006 8:14 AM
JohnHood33$19.9925%Dec 10, 2002 5:14 AM
ClarkKent18$15.8944%Jan 12, 2003 11:14 AM
BruceAlmighty45$153.1944%Jan 18, 2001 9:12 AM
BruceEvans22$13.1911%Jan 18, 2007 9:12 AM
First Name Last Name Age Total Discount Date
PeterParker28$9.9920%Jul 6, 2006 8:14 AM
JohnHood33$19.9925%Dec 10, 2002 5:14 AM
ClarkKent18$15.8944%Jan 12, 2003 11:14 AM
BruceAlmighty45$153.1944%Jan 18, 2001 9:12 AM
BruceEvans22$13.1911%Jan 18, 2007 9:12 AM

Javascript


	

HTML