• Oct 27, 2014 - added a demo to the home wiki page showing how to apply jQuery's selectmenu widget to a filter cell without using the filter formatter functions.
  • As of v2.17.5, if writing a custom filterFormatter function, you'll need to call an additional function after initialization has completed so the "filterInit" event isn't triggered prematurely. See the "Custom Filter Formatter Function Information" section below for more details.
  • In v2.17.0, the filter_formatter column can also be referenced by using a jQuery selector (e.g. class name or ID).
  • In v2.16.0, the filter_placeholder option was added. See the jQuery UI Datepicker Range Selector section for more details.
  • In v2.15.0, the following changes were made:
    • These updated filter widget functions are not completely backward compatible with older versions of the filter widget. Please update both!
    • Added compare & selected options:
      • These options allow the adding of a comparison operator selector to the cell (e.g. >, >=, <, <=, etc).
      • If any cellText is included, it is now wrapped in a label with a class name of "compare-select-label" and "compare-select-label#" (where "#" is the column index).
      • The selector has a class name of "compare-select" and "compare-select#" (where "#" is the column index)
      • Whichever type of input that is added to the cell is then wrapped in a div with class "compare-select-wrapper" and "compare-select-wrapper#" (where "#" is the column index).
      • These class names allow styling of an individual filter to keep elements in line, or however you wish to style it.
        <!-- rendered filter cell (first column) -->
        <td>
        <!-- cellText -->
        <label class="compare-select-label compare-select-label0">Rank:</label>
        <!-- compare: [ '=', '>=', '<=' ] -->
        <select class="compare-select compare-select0">
        <option>=</option>
        <option>&gt;=</option>
        <option selected>&lt;=</option>
        </select>
        <!-- wrapped selector element -->
        <div class="compare-select-wrapper compare-select-wrapper0">
        <div class="slider slider0><!-- jQuery UI Slider gets added here --></div>
        </div>
        <!-- hidden input -->
        <input class="filter tablesorter-filter" type="hidden" value="" data-column="0">
        </td>
    • Filter reset now sets these filters to their default values, not an empty string.
    • Updated to now properly restore saved filters.
    • Added endOfDay option for jQuery UI Datepicker.
      • When true search dates will include all times from the date chosen when a comparison is made of dates "less than" the set date.
      • Example 1: if a table entry has a date of "Jan 14, 2014 11:23 AM" and the filter search is set to , the table entry will be included in the search; the default set time would otherwise be "1/14/2014 00:00:00" and not include the entry from "11:23 AM". So, the endOfDay option sets the time to "23:59:59".
      • Example 2: if searching for one specific date, this option will now search for all times within that day. For example, searching for , and the results will include dates from 1/20/2014 00:00:00 to 1/20/2014 23:59:59.
      • When comparing dates greater than the set date, the time will be set to midnight; so this option will not be applied.
      • Example 3: in two date inputs, the endOfDay time is only applied to the "to" input; search for
      • This option is available in both the comparison (one input) and range (two inputs; "to" date input only) date pickers.
  • As of tablesorter version 2.9+, this widget can no longer be applied to versions of tablesorter prior to version 2.8.
  • This page shows you how to add a few jQuery UI widgets to interact with the filter widget using the filter_formatter option.
  • Custom filter widget option filter_formatter was added in version 2.7.7.
  • jQuery v1.4.3+ required.

Demo


Rank
Age
Total (range)
Discount
Date (one input)
Date (two inputs; range)
125$5.9522%Jun 26, 2013 7:22 AMJun 26, 2013 7:22 AM
1112$82.995%Aug 21, 2013 12:21 PMAug 21, 2013 12:21 PM
1251$99.2918%Oct 13, 2013 1:15 PMOct 13, 2013 1:15 PM
5128$9.9920%Jul 6, 2013 8:14 AMJul 6, 2013 8:14 AM
2133$19.9925%Dec 10, 2012 5:14 AMDec 10, 2012 5:14 AM
01318$65.8945%Jan 12, 2013 11:14 AMJan 12, 2013 11:14 AM
00545$153.1945%Jan 18, 2014 9:12 AMJan 18, 2014 9:12 AM
103$5.294%Jan 8, 2013 5:11 PMJan 8, 2013 5:11 PM
1624$14.1914%Jan 14, 2014 11:23 AMJan 14, 2014 11:23 AM
6622$13.1911%Jan 18, 2013 9:12 AMJan 18, 2013 9:12 AM
10018$55.2015%Feb 12, 2013 7:23 PMFeb 12, 2013 7:23 PM
5565$123.0032%Jan 20, 2014 1:12 PMJan 20, 2014 1:12 PM
925$22.0917%Jun 11, 2013 10:55 AMJun 11, 2013 10:55 AM
1312$19.9918%Jan 20, 2014 7:45 PMJan 20, 2014 7:45 PM
7358$129.1939%Jan 20, 2014 10:11 AMJan 20, 2014 10:11 AM

Page Header

<!-- jQuery UI for range slider -->
<link rel="stylesheet" href="css/jquery-ui.min.css">
<script src="js/jquery-ui.min.js"></script>

<!-- tablesorter plugin -->
<link rel="stylesheet" href="../css/theme.blue.css">
<script src="../js/jquery.tablesorter.js"></script>
<script src="../js/jquery.tablesorter.widgets.js"></script>

<!-- filter formatter code -->
<link rel="stylesheet" href="../css/filter.formatter.css">
<script src="../js/widgets/widget-filter-formatter-jui.js"></script>

CSS

/* css needed to get compare selector & slider in-line */
.compare-select-wrapper { min-width: 60%; float: right; }

Javascript

$(function() {

// call the tablesorter plugin
$("table").tablesorter({
theme : 'jui',
headerTemplate : '{content}{icon}',
// hidden filter input/selects will resize the columns, so try to minimize the change
widthFixed : true,
// initialize zebra striping and filter widgets
widgets : ["zebra", "filter", "stickyHeaders", "uitheme"],
widgetOptions : {
// Use the $.tablesorter.storage utility to save the most recent filters
filter_saveFilters : true,
// jQuery selector string of an element used to reset the filters
filter_reset : 'button.reset',
// add custom selector elements to the filter row
filter_formatter : {

// Rank (jQuery selector added v2.17.0)
'th:contains("Rank")' : function($cell, indx) {
return $.tablesorter.filterFormatter.uiSlider( $cell, indx, {
delayed : true,
valueToHeader : false,
cellText : 'Rank:',
compare : [ '=', '>=', '<=' ],
selected : 2, // zero-based index of compare starting selected value
// jQuery UI slider options
value : 100,
min : 0,
max : 100
});
},

// Age
1 : function($cell, indx) {
return $.tablesorter.filterFormatter.uiSlider( $cell, indx, {
delayed : false,
valueToHeader : false,
exactMatch : false,
allText : 'all', // this is ignored when compare is not empty
compare : [ '=', '>=', '<=' ],
selected : 1,
// jQuery UI slider options
value : 1,
min : 1,
max : 65
});
},

// Total (jQuery selector added v2.17.0)
'.total' : function($cell, indx) {
return $.tablesorter.filterFormatter.uiRange( $cell, indx, {
delayed : false,
valueToHeader : false,
// jQuery UI slider options
values : [1, 160],
min : 1,
max : 160
});
},

// Discount
3 : function($cell, indx) {
return $.tablesorter.filterFormatter.uiSpinner( $cell, indx, {
delayed : true,
addToggle : false,
exactMatch : true,
compare : [ '', '=', '>=', '<=' ],
selected : 2,
// jQuery UI spinner options
min : 0,
max : 45,
value : 1,
step : 1
});
},

// Date (one input)
4 : function($cell, indx) {
return $.tablesorter.filterFormatter.uiDateCompare( $cell, indx, {
cellText : 'Dates', // text added before the input
compare : [ '', '=', '>=', '<=' ],
selected : 3,
// jQuery UI datepicker options
// defaultDate : '1/1/2014', // default date
changeMonth : true,
changeYear : true

});
},

// Date (two inputs)
5 : function($cell, indx) {
return $.tablesorter.filterFormatter.uiDatepicker( $cell, indx, {
// from : '08/01/2013', // default from date
// to : '1/18/2014', // default to date
changeMonth : true,
changeYear : true
});
}
},

// added v2.16
filter_placeholder : {
from : 'From...',
to : 'To...'
}
}
});

});

HTML

<table class="tablesorter">
<thead>
<tr>
<th>Rank</th>
<th>Age</th>
<th class="total">Total (range)</th>
<th>Discount</th>
<th data-placeholder="Try 1/18/2013">Date (one input)</th>
<th>Date (two inputs; range)</th>
</tr>
</thead>
<tbody>
<tr><td>1</td><td>25</td><td>$5.95</td><td>22%</td><td>Jun 26, 2013 7:22 AM</td><td>Jun 26, 2013 7:22 AM</td></tr>
<tr><td>11</td><td>12</td><td>$82.99</td><td>5%</td><td>Aug 21, 2013 12:21 PM</td><td>Aug 21, 2013 12:21 PM</td></tr>
<tr><td>12</td><td>51</td><td>$99.29</td><td>18%</td><td>Oct 13, 2013 1:15 PM</td><td>Oct 13, 2013 1:15 PM</td></tr>
<tr><td>51</td><td>28</td><td>$9.99</td><td>20%</td><td>Jul 6, 2013 8:14 AM</td><td>Jul 6, 2013 8:14 AM</td></tr>
<tr><td>21</td><td>33</td><td>$19.99</td><td>25%</td><td>Dec 10, 2012 5:14 AM</td><td>Dec 10, 2012 5:14 AM</td></tr>
<tr><td>013</td><td>18</td><td>$65.89</td><td>45%</td><td>Jan 12, 2013 11:14 AM</td><td>Jan 12, 2013 11:14 AM</td></tr>
<tr><td>005</td><td>45</td><td>$153.19</td><td>45%</td><td>Jan 18, 2014 9:12 AM</td><td>Jan 18, 2014 9:12 AM</td></tr>
<tr><td>10</td><td>3</td><td>$5.29</td><td>4%</td><td>Jan 8, 2013 5:11 PM</td><td>Jan 8, 2013 5:11 PM</td></tr>
<tr><td>16</td><td>24</td><td>$14.19</td><td>14%</td><td>Jan 14, 2014 11:23 AM</td><td>Jan 14, 2014 11:23 AM</td></tr>
<tr><td>66</td><td>22</td><td>$13.19</td><td>11%</td><td>Jan 18, 2013 9:12 AM</td><td>Jan 18, 2013 9:12 AM</td></tr>
<tr><td>100</td><td>18</td><td>$55.20</td><td>15%</td><td>Feb 12, 2013 7:23 PM</td><td>Feb 12, 2013 7:23 PM</td></tr>
<tr><td>55</td><td>65</td><td>$123.00</td><td>32%</td><td>Jan 20, 2014 1:12 PM</td><td>Jan 20, 2014 1:12 PM</td></tr>
<tr><td>9</td><td>25</td><td>$22.09</td><td>17%</td><td>Jun 11, 2013 10:55 AM</td><td>Jun 11, 2013 10:55 AM</td></tr>
<tr><td>13</td><td>12</td><td>$19.99</td><td>18%</td><td>Jan 20, 2014 7:45 PM</td><td>Jan 20, 2014 7:45 PM</td></tr>
<tr><td>73</td><td>58</td><td>$129.19</td><td>39%</td><td>Jan 20, 2014 10:11 AM</td><td>Jan 20, 2014 10:11 AM</td></tr>
</tbody>
</table>

Next up: jQuery custom filter widget formatter (HTML5 Elements) ››
PrevNext
SuMoTuWeThFrSa
  12345
6789101112
13141516171819
20212223242526
27282930