2013-02-17 19:53:33 +00:00
<!DOCTYPE html>
2011-08-01 03:15:17 +00:00
< html >
< head >
< meta charset = "utf-8" >
< title > jQuery plugin: Tablesorter 2.0 - Dealing with text strings in numerical sorts< / title >
<!-- jQuery -->
2014-05-21 22:09:23 +00:00
< script src = "js/jquery-latest.min.js" > < / script >
2011-08-01 03:15:17 +00:00
<!-- Demo stuff -->
< link rel = "stylesheet" href = "css/jq.css" >
2013-01-26 15:21:13 +00:00
< link href = "css/prettify.css" rel = "stylesheet" >
< script src = "js/prettify.js" > < / script >
2011-08-01 03:15:17 +00:00
< script src = "js/docs.js" > < / script >
<!-- Tablesorter: required -->
2012-09-27 19:57:19 +00:00
< link rel = "stylesheet" href = "../css/theme.blue.css" >
2011-08-01 03:15:17 +00:00
< style >
th { width: 10%; }
< / style >
< script src = "../js/jquery.tablesorter.js" > < / script >
< script id = "js" > $ ( f u n c t i o n ( ) {
// call the tablesorter plugin
$("table").tablesorter({
2012-09-27 19:57:19 +00:00
theme : 'blue',
2012-04-20 16:09:43 +00:00
// default strings setting
stringTo: "max",
// columns 2 & 3 (zero-based index) set using headers option
// columns 4+ set using header class name: "string-max", "string-min", "string-top", "string-bottom" and "string-none"
2011-08-01 03:15:17 +00:00
headers: {
2012-04-20 16:09:43 +00:00
1: { sorter: "digit", empty : "top" }, // sort empty cells to the top
2: { sorter: "digit", string: "max" }, // non-numeric content is treated as a MAX value
3: { sorter: "digit", string: "min" } // non-numeric content is treated as a MIN value
2011-08-01 03:15:17 +00:00
}
2012-04-20 16:09:43 +00:00
2011-08-01 03:15:17 +00:00
});
});< / script >
< / head >
< body >
< div id = "banner" >
< h1 > table< em > sorter< / em > < / h1 >
< h2 > Dealing with text strings in numerical sorts< / h2 >
< h3 > Flexible client-side table sorting< / h3 >
< a href = "index.html" > Back to documentation< / a >
< / div >
< div id = "main" >
< p class = "tip" >
< em > NOTE!< / em >
< ul >
2011-09-08 16:28:10 +00:00
< li > This functionality is new as of version 2.0.10 (not part of the original plugin).< / li >
2012-09-27 19:57:19 +00:00
< li > When a column is sorted numerically ( < code > sorter:"digit"< / code > ) any text in that column will, by default, be given a < em > zero< / em > value. Sort the last column (#9) to see the problem with this method.< / li >
< li > Overall < code > stringTo< / code > option added in version 2.1.16.< / li >
2012-04-20 16:09:43 +00:00
< li > String options changed in version 2.1.16; setting the value to:
< ul >
2012-09-27 19:57:19 +00:00
< li > < code > "max"< / code > will treat any text in that column as a value greater than the < em > max< / em > (more positive) value. Renamed from "max+".< / li >
< li > < code > "min"< / code > will treat any text in that column as a value greater than the < em > min< / em > (more negative) value. Renamed from "max-".< / li >
< li > < code > "top"< / code > will always sort the text to the top of the column.< / li >
< li > < code > "bottom"< / code > will always sort the text to the bottom of the column.< / li >
< li > < code > "none"< / code > or < code > "zero"< / code > will treat the text as if it has a value of zero.< / li >
2012-04-20 16:09:43 +00:00
< / ul >
< / li >
2012-09-27 19:57:19 +00:00
< li > Individual columns can be modified by adding the following (they all do the same thing), set in order of priority:
2012-04-20 16:09:43 +00:00
< ul >
2012-09-27 19:57:19 +00:00
< li > jQuery data < code > data-string="top"< / code > .< / li >
< li > metadata < code > class="{ string: 'top'}"< / code > . This requires the metadata plugin.< / li >
< li > headers option < code > headers : { 0 : { string : 'top' } }< / code > .< / li >
< li > header class name < code > class="string-top"< / code > .< / li >
< li > Overall < code > stringTo< / code > option.< / li >
2012-04-20 16:09:43 +00:00
< / ul >
< / li >
< li > Sort columns three through eight to see how the sort has changed. Note that the text is sorted separately from the numeric values.< / li >
2012-11-26 19:16:48 +00:00
< li > The < code > emptyTo< / code > option defaults to bottom, so all empty cells will sort at the bottom of the table, except for the second column.< / li >
2011-08-01 03:15:17 +00:00
< / ul >
2014-07-18 01:42:01 +00:00
< p >
2011-08-01 03:15:17 +00:00
< h1 > Demo< / h1 >
< div id = "demo" > < table >
< thead >
< tr >
< th > Account #< / th >
< th > Difference< / th >
2012-04-20 16:09:43 +00:00
< th > 3: Ratings (max)< / th >
< th > 4: Ratings (min)< / th >
< th class = "string-max" > 5: Change (max)< / th >
< th class = "string-min" > 6: Change (min)< / th >
< th class = "string-top" > 7: Change (top)< / th >
< th class = "string-bottom" > 8: Change (bottom)< / th >
< th class = "string-none" > 9: Change (zero)< / th >
2011-08-01 03:15:17 +00:00
< / tr >
< / thead >
< tbody >
< tr >
< td > A43< / td >
< td > -35< / td >
< td > 01< / td >
< td > 01< / td >
< td > -.1< / td >
< td > -.1< / td >
< td > -.1< / td >
2012-04-20 16:09:43 +00:00
< td > -.1< / td >
< td > -.1< / td >
2011-08-01 03:15:17 +00:00
< / tr >
< tr >
< td > A255< / td >
< td > 33< / td >
< td > 02< / td >
< td > 02< / td >
< td > N/A #1< / td >
< td > N/A #1< / td >
< td > N/A #1< / td >
2012-04-20 16:09:43 +00:00
< td > N/A #1< / td >
< td > N/A #1< / td >
2011-08-01 03:15:17 +00:00
< / tr >
< tr >
< td > A33< / td >
< td > 2< / td >
< td > 03< / td >
< td > 03< / td >
< td > N/A #2< / td >
< td > N/A #2< / td >
< td > N/A #2< / td >
2012-04-20 16:09:43 +00:00
< td > N/A #2< / td >
< td > N/A #2< / td >
2011-08-01 03:15:17 +00:00
< / tr >
< tr >
< td > A1< / td >
< td > -5< / td >
< td > 04< / td >
< td > 04< / td >
< td > -8.4< / td >
< td > -8.4< / td >
< td > -8.4< / td >
2012-04-20 16:09:43 +00:00
< td > -8.4< / td >
< td > -8.4< / td >
2011-08-01 03:15:17 +00:00
< / tr >
< tr >
< td > A102< / td >
< td > 99< / td >
< td > 05< / td >
< td > 05< / td >
< td > -2.2< / td >
< td > -2.2< / td >
< td > -2.2< / td >
2012-04-20 16:09:43 +00:00
< td > -2.2< / td >
< td > -2.2< / td >
2011-08-01 03:15:17 +00:00
< / tr >
< tr >
< td > A10< / td >
< td > -1< / td >
< td > 06< / td >
< td > 06< / td >
< td > 97.4< / td >
< td > 97.4< / td >
< td > 97.4< / td >
2012-04-20 16:09:43 +00:00
< td > 97.4< / td >
< td > 97.4< / td >
2011-08-01 03:15:17 +00:00
< / tr >
< tr >
< td > A02< / td >
< td > 0< / td >
< td > 07< / td >
< td > 07< / td >
< td > 23.6< / td >
< td > 23.6< / td >
< td > 23.6< / td >
2012-04-20 16:09:43 +00:00
< td > 23.6< / td >
< td > 23.6< / td >
2011-08-01 03:15:17 +00:00
< / tr >
< tr >
< td > A55< / td >
< td > 44< / td >
< td > < / td >
< td > < / td >
< td > 11.4< / td >
< td > 11.4< / td >
< td > 11.4< / td >
2012-04-20 16:09:43 +00:00
< td > 11.4< / td >
< td > 11.4< / td >
2011-08-01 03:15:17 +00:00
< / tr >
< tr >
< td > A87< / td >
< td > 04< / td >
< td > NR< / td >
< td > NR< / td >
< td > 5.2< / td >
< td > 5.2< / td >
< td > 5.2< / td >
2012-04-20 16:09:43 +00:00
< td > 5.2< / td >
< td > 5.2< / td >
2011-08-01 03:15:17 +00:00
< / tr >
< tr >
< td > A012< / td >
2012-04-20 16:09:43 +00:00
< td > < / td >
2011-08-01 03:15:17 +00:00
< td > NR< / td >
< td > NR< / td >
< td > < / td >
< td > < / td >
< td > < / td >
2012-04-20 16:09:43 +00:00
< td > < / td >
< td > < / td >
2011-08-01 03:15:17 +00:00
< / tr >
< / tbody >
< / table > < / div >
< h1 > Javascript< / h1 >
< div id = "javascript" >
2013-01-26 15:21:13 +00:00
< pre class = "prettyprint lang-javascript" > < / pre >
2011-08-01 03:15:17 +00:00
< / div >
< h1 > HTML< / h1 >
< div id = "html" >
2013-01-26 15:21:13 +00:00
< pre class = "prettyprint lang-html" > < / pre >
2011-08-01 03:15:17 +00:00
< / div >
< div class = "next-up" >
< hr / >
2011-10-26 06:50:02 +00:00
Next up: < a href = "example-parsers-class-name.html" > Disable or set the column parser using class names › › < / a >
2011-08-01 03:15:17 +00:00
< / div >
< / div >
< / body >
< / html >