In v2.15.0 the compare option was updated to allow adding a selector along with the input. The selected option allows choosing the default setting.
This example shows how you can add an HTML5 range input slider to filter column content.
The filter_formatter function provided in the extra "widget-filter-formatter-html5.js" file is used to add this custom control within the filter row.
Make sure to include all values within the selected range, otherwise rows outside of this range will be forever hidden.
Add the following code to apply an HTML5 range slider to the filter row:
$(function() {
$("table").tablesorter({
theme: 'blue',
// initialize zebra striping and filter widgets
widgets: ["zebra", "filter"],
widgetOptions : {
// 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
0 : function($cell, indx){
return $.tablesorter.filterFormatter.html5Range( $cell, indx, {
value: 0,
min: 0,
max: 100,
delayed: true,
valueToHeader: true,
compare : [ '=', '>=', '<=' ],
selected: 1
});
},
// Total
4 : function($cell, indx){
return $.tablesorter.filterFormatter.html5Range( $cell, indx, {
value: 0,
min: 0,
max: 150,
delayed: true,
valueToHeader: true,
compare : '>='
});
}
}
}
});
});
By default, this code has the valueToHeader option set to true to add the slider value to the header cell above the filter.
The tooltip above the slider is NOT added in this example because the slider handle is not a separate element. But if you are interested, you can use this code by Chris Coyier to animate a range slider bubble.
Another option named exactMatch was added to allow exact or general matching of column content.
Notice that the left-most value, zero in this case, will clear the column filter to allow a method to show all column content. You can modify the "all" text using the allText option.
A search delay option was added in v2.7.11 (time set by filter_searchDelay option). It can be disabled by setting the delayed option to false.
This example shows how you can add an HTML5 color input to filter column content.
The filter_formatter function is used to add a custom control within the filter row, but a hidden input is still required to store the filter value.
Add the following code to apply a color input to the filter row:
$(function() {
$("table").tablesorter({
theme: 'blue',
// 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"],
widgetOptions : {
// 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 : {
// Color
1 : function($cell, indx){
return $.tablesorter.filterFormatter.html5Color( $cell, indx, {
value: '#000000',
addToggle: true,
exactMatch: true,
valueToHeader: false
});
}
}
}
});
});
This color selector will only output the color as a hex value with a hash followed by six characters (#000000).
By default, this code has the valueToHeader option set to false. The currently selected color is added to a span within the cell by default.
Another option named exactMatch was added to allow exact or general matching of column content, in case you have multiple colors in one cell.
This selector includes a toggle button. The toggle button is added by default, but if you don't want it, set the addToggle option to false. Without the toggle button, the filter is always active.
In v2.15.0 the compare option was updated to allow adding a selector along with the input. The selected option allows choosing the default setting.
This example shows how you can add an HTML5 number spinner to the filter column content.
The filter_formatter function provided in the extra "widget-filter-formatter-html5.js" file is used to add this custom control within the filter row.
Add the following code to apply an HTML spinner to filter a column:
$(function() {
$("table").tablesorter({
theme: 'blue',
// 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"],
widgetOptions : {
// 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 : {
// Age
3: function($cell, indx){
return $.tablesorter.filterFormatter.html5Number( $cell, indx, {
value: 1,
min: 1,
max: 65,
delayed: true,
addToggle: true,
exactMatch: true,
compare: ''
});
},
// Discount
5: function($cell, indx){
return $.tablesorter.filterFormatter.html5Number( $cell, indx, {
value: 1,
min: 1,
max: 44,
delayed: true,
addToggle: false,
compare: [ '<=', '=', '>=' ],
selected: 2
});
}
}
}
});
});
This is spinner includes a toggle button. The toggle button is added by default, but if you don't want it, set the addToggle option to false. Without the toggle button, the filter is always active.
Another option named exactMatch was added to allow exact or general matching of column content.
A search delay option was added in v2.7.11 (time set by filter_searchDelay option). It can be disabled by setting the delayed option to false.