• This widget will only work in tablesorter version 2.16+ and jQuery version 1.7+.
  • It allows you to add custom formatting to table columns.
  • You have the option of storing the original cell text within the table cell data-attribute to maintain the sort order.
  • This widget is not optimized for large tables; but it only runs on initialization and after any updates have occurred.

Demo

Super Hero
Super Car
Image Links
Added
SupermanBugatti VeyronSearch The Duck15 minutes ago
FlashHennessey VenomSearch The Duck2 weeks ago
BatmanKoenigsegg AgeraSearch The Duck5 hours ago
Green LanternSSC Ultimate AeroSearch The Duckjust now
Howard the DuckKoenigsegg CCXSearch The Duck23 months ago
Wonder WomanMcLaren F1Search The Duck3 years ago

Javascript

$(function() {

$('.tablesorter').tablesorter({
theme: 'blue',
widgets: ['formatter', 'filter'],
widgetOptions: {
filter_matchType : { 'input': 'match', 'select': 'exact' },
formatter_column: {
'.emphasize' : function( text, data ) {
return '<strong>' + text + '</strong>';
},
'.supercar' : function( text, data ) {
if ( text === '' ) { return ''; }
// replace table cell with a link
return '<a href="https://www.google.com/search?tbm=isch&q=' + text.replace(/\s/g, '+') + '">' + text + '</a>';
},
'.date' : function( text, data ) {
var date = new Date( text );
if ( date instanceof Date && isFinite( date ) ) {
data.$cell.attr( data.config.textAttribute, text );
return '<em>' + prettyDate( date ) + '</em>';
}
return text;
},
'.duckify' : function( text, data ) {
if ( text === '' ) { return ''; }
// add text to data-attribute; this overrides the parser
data.$cell.attr( data.config.textAttribute, text );
// replace table cell with a link
return '<a href="https://duckduckgo.com/?ia=images&q=' + text + '">Search The Duck</a>';
},
'.blue' : function( text, data ) {
return '<span class="blue">' + text + '</span>';
}
}
}
});

});

/*
* JavaScript Pretty Date (MODIFIED)
* Copyright (c) 2011 John Resig (ejohn.org)
* Licensed under the MIT and GPL licenses.
*/
function prettyDate(date) {
var diff = (((new Date()).getTime() - date.getTime()) / 1000),
day_diff = Math.floor(diff / 86400);
if ( isNaN(day_diff) || day_diff < 0 ) { return ''; }
return day_diff == 0 && (
diff < 60 && 'just now' ||
diff < 120 && '1 minute ago' ||
diff < 3600 && Math.floor( diff / 60 ) + ' minutes ago' ||
diff < 7200 && '1 hour ago' ||
diff < 86400 && Math.floor( diff / 3600 ) + ' hours ago') ||
day_diff == 1 && 'Yesterday' ||
day_diff < 7 && day_diff + ' days ago' ||
day_diff < 61 && Math.ceil( day_diff / 7 ) + ' weeks ago' ||
day_diff < 730 && Math.floor( day_diff / 30 ) + ' months ago' ||
Math.floor( day_diff / 365 ) + ' years ago';
}

CSS

/* demo styling */
#table strong {
color: #a00;
}

HTML

<table id="table" class="tablesorter">
<thead>
<tr>
<th class="emphasize filter-exact">Super Hero</th>
<th class="supercar">Super Car</th>
<th class="duckify filter-select">Image Links</th>
<th class="date">Added</th>
</tr>
</thead>
<tbody>
<!-- Added column dates are dynamically updated for this demo -->
<tr><td>Superman</td><td>Bugatti Veyron</td><td>Duckie</td><td>3/15/2025 20:35:56</td></tr>
<tr><td>Flash</td><td>Hennessey Venom</td><td>Horse</td><td>3/6/2025 14:37:36</td></tr>
<tr><td>Batman</td><td>Koenigsegg Agera</td><td>Elephant</td><td>3/15/2025 15:17:36</td></tr>
<tr><td>Green Lantern</td><td>SSC Ultimate Aero</td><td>Cow</td><td>3/15/2025 20:50:56</td></tr>
<tr><td>Howard the Duck</td><td>Koenigsegg CCX</td><td>Pizza</td><td>4/21/2023 10:10:56</td></tr>
<tr><td>Wonder Woman</td><td>McLaren F1</td><td>Tiger</td><td>1/13/2022 11:4:16</td></tr>
</tbody>
</table>