2011-07-17 15:01:18 +00:00
<!DOCTYPE html>
< html >
2011-06-22 23:19:27 +00:00
< head >
2016-01-10 22:24:57 +00:00
< meta charset = "utf-8" >
< title > jQuery tablesorter 2.0 - Dealing with markup inside cells< / title >
2011-06-22 23:19:27 +00:00
<!-- jQuery -->
2014-05-21 22:09:23 +00:00
< script src = "js/jquery-latest.min.js" > < / script >
2011-06-22 23:19:27 +00:00
<!-- Demo stuff -->
2011-07-17 15:01:18 +00:00
< 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-07-17 15:01:18 +00:00
< script src = "js/docs.js" > < / script >
2011-06-22 23:19:27 +00:00
<!-- Tablesorter: required -->
2012-09-27 19:57:19 +00:00
< link rel = "stylesheet" href = "../css/theme.blue.css" >
2011-07-17 15:01:18 +00:00
< script src = "../js/jquery.tablesorter.js" > < / script >
2011-06-22 23:19:27 +00:00
2011-07-17 15:01:18 +00:00
< script id = "js" > $ ( f u n c t i o n ( ) {
2011-06-22 23:19:27 +00:00
// call the tablesorter plugin
$("table").tablesorter({
2012-09-27 19:57:19 +00:00
theme : 'blue',
2011-08-19 06:24:29 +00:00
/*
// define an overall custom text extraction function
2012-03-11 14:45:10 +00:00
textExtraction: function(node, table, cellIndex) {
2011-07-17 15:01:18 +00:00
return $(node).text();
2011-06-22 23:19:27 +00:00
}
2011-08-19 06:24:29 +00:00
*/
2011-08-19 16:40:12 +00:00
// Define a custom text extraction function for each column
// In this example, textExtraction 1-5 functions don't really need to
// be defined, since they can also be obtained using `$(node).text()`
2011-08-19 06:24:29 +00:00
textExtraction: {
2012-03-11 14:45:10 +00:00
0: function(node, table, cellIndex){ return $(node).find("strong").text(); },
1: function(node, table, cellIndex){ return $(node).find("div").text(); },
2: function(node, table, cellIndex){ return $(node).find("span").text(); },
3: function(node, table, cellIndex){ return $(node).find("em").text(); },
4: function(node, table, cellIndex){ return $(node).find("a").text(); },
2014-05-14 12:51:44 +00:00
'.date' : function(node, table, cellIndex){ return $(node).find("u").text(); }
2011-08-19 06:24:29 +00:00
}
2011-07-17 15:01:18 +00:00
2011-06-22 23:19:27 +00:00
});
2011-07-17 15:01:18 +00:00
});< / script >
2011-06-22 23:19:27 +00:00
< / head >
< body >
2011-07-17 15:01:18 +00:00
2011-06-22 23:19:27 +00:00
< div id = "banner" >
2011-08-19 06:24:29 +00:00
< h1 > table< strong > sorter< / strong > < / h1 >
2011-06-22 23:19:27 +00:00
< h2 > Dealing with markup inside cells< / h2 >
< h3 > Flexible client-side table sorting< / h3 >
< a href = "index.html" > Back to documentation< / a >
< / div >
2011-07-17 15:01:18 +00:00
2011-06-22 23:19:27 +00:00
< div id = "main" >
2011-08-19 06:24:29 +00:00
< p class = "tip" >
2011-09-08 16:28:10 +00:00
< em > NOTE!< / em >
2016-01-10 22:24:57 +00:00
< / p >
< ul >
< li > In < span class = "version updated" > v2.17.0< / span > , the < code > textExtraction< / code > column can also be referenced by using a jQuery selector (e.g. class name or ID).< / li >
< li > The textExtraction function setting for each column was added in version 2.0.12 (not part of the original plugin).< / li >
< li > The "First Name" column is sorting by the contents of the < strong> tag (in red).< / li >
< li > Added "table" and "cellIndex" variables to the textExtraction function (v2.1.2).< / li >
< / ul >
2011-08-19 06:24:29 +00:00
2011-06-22 23:19:27 +00:00
< h1 > Demo< / h1 >
2011-07-17 15:01:18 +00:00
< div id = "demo" > < table class = "tablesorter" >
< thead >
< tr >
< th > First Name< / th >
< th > Last Name< / th >
< th > Age< / th >
< th > Total< / th >
< th > Discount< / th >
2014-05-14 12:51:44 +00:00
< th class = "date" > Date< / th >
2011-07-17 15:01:18 +00:00
< / tr >
< / thead >
< tbody >
< tr >
2011-08-19 06:24:29 +00:00
< td > Mr. < strong > Peter< / strong > < / td >
< td > < div > Parker< / div > < / td >
< td > < span > 28< / span > < / td >
< td > < em > $9.99< / em > < / td >
< td > < a href = "#" > 20%< / a > < / td >
< td > < u > Jul 6, 2006 8:14 AM< / u > < / td >
2011-07-17 15:01:18 +00:00
< / tr >
< tr >
2011-08-19 06:24:29 +00:00
< td > Dr. < strong > John< / strong > < / td >
< td > < div > Hood< / div > < / td >
< td > < span > 33< / span > < / td >
< td > < em > $19.99< / em > < / td >
< td > < a href = "#" > 25%< / a > < / td >
< td > < u > Dec 10, 2002 5:14 AM< / u > < / td >
2011-07-17 15:01:18 +00:00
< / tr >
< tr >
2011-08-19 06:24:29 +00:00
< td > Rep < strong > Clark< / strong > < / td >
< td > < div > Kent< / div > < / td >
< td > < span > 18< / span > < / td >
< td > < em > $15.89< / em > < / td >
< td > < a href = "#" > 44%< / a > < / td >
< td > < u > Jan 12, 2003 11:14 AM< / u > < / td >
2011-07-17 15:01:18 +00:00
< / tr >
< tr >
2011-08-19 06:24:29 +00:00
< td > Rev < strong > Bruce< / strong > < / td >
< td > < div > Almighty< / div > < / td >
< td > < span > 45< / span > < / td >
< td > < em > $153.19< / em > < / td >
< td > < a href = "#" > 44%< / a > < / td >
< td > < u > Jan 18, 2001 9:12 AM< / u > < / td >
2011-07-17 15:01:18 +00:00
< / tr >
< tr >
2011-08-19 06:24:29 +00:00
< td > Capt < strong > Bruce< / strong > < / td >
< td > < div > Evans< / div > < / td >
< td > < span > 22< / span > < / td >
< td > < em > $13.19< / em > < / td >
< td > < a href = "#" > 11%< / a > < / td >
< td > < u > Jan 18, 2007 9:12 AM< / u > < / td >
2011-07-17 15:01:18 +00:00
< / tr >
< / tbody >
< / table > < / div >
2011-06-22 23:19:27 +00:00
< h1 > Javascript< / h1 >
< div id = "javascript" >
2013-01-26 15:21:13 +00:00
< pre class = "prettyprint lang-javascript" > < / pre >
2011-06-22 23:19:27 +00:00
< / div >
< h1 > HTML< / h1 >
< div id = "html" >
2013-01-26 15:21:13 +00:00
< pre class = "prettyprint lang-html" > < / pre >
2011-06-22 23:19:27 +00:00
< / div >
2011-07-17 15:01:18 +00:00
< div class = "next-up" >
< hr / >
2011-10-26 06:50:02 +00:00
Next up: < a href = "example-apply-widget.html" > Applying widgets › › < / a >
2011-07-17 15:01:18 +00:00
< / div >
2011-06-22 23:19:27 +00:00
< / div >
< / body >
< / html >