2015-12-13 22:24:42 +00:00
|
|
|
/*! Widget: filter, insideRange filter type - updated 12/10/2015 (v2.25.0) */
|
2015-02-24 06:00:52 +00:00
|
|
|
;(function($){
|
2015-07-23 04:29:51 +00:00
|
|
|
'use strict';
|
2015-02-24 06:00:52 +00:00
|
|
|
|
|
|
|
// Add insideRange filter type
|
|
|
|
// ============================
|
|
|
|
// This allows you to enter a number (e.g. 8) and show the
|
|
|
|
// resulting rows that will have that query within it's range
|
|
|
|
// demo at http://mottie.github.io/tablesorter/docs/example-widget-filter-custom-search2.html
|
|
|
|
var ts = $.tablesorter,
|
|
|
|
isDigit = /\d+/,
|
|
|
|
range = /\s+-\s+/,
|
|
|
|
parseNumber = function(num) {
|
|
|
|
return isNaN(num) ? num : parseFloat(num);
|
|
|
|
};
|
|
|
|
|
|
|
|
ts.filter.types.insideRange = function( c, data ) {
|
2015-12-11 02:09:51 +00:00
|
|
|
// don't look for an inside range if "any" match is enabled... multiple "-" really screw things up
|
|
|
|
if ( !data.anyMatch && isDigit.test( data.iFilter ) && range.test( data.iExact ) ) {
|
2015-02-24 06:00:52 +00:00
|
|
|
var t, val, low, high,
|
2015-11-21 05:11:12 +00:00
|
|
|
index = data.index,
|
|
|
|
cell = data.$cells[ index ],
|
2015-02-24 06:00:52 +00:00
|
|
|
parts = data.iExact.split( range ),
|
2015-12-11 02:09:51 +00:00
|
|
|
format = c.parsers[data.index] && c.parsers[data.index].format;
|
|
|
|
// the cell does not contain a range or the parser isn't defined
|
|
|
|
if ( parts && parts.length < 2 || typeof format !== 'function' ) {
|
2015-02-24 06:00:52 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
// format each side part of the range using the assigned parser
|
2015-11-21 05:11:12 +00:00
|
|
|
low = parseNumber( format( parts[0], c.table, cell, index ) );
|
|
|
|
high = parseNumber( format( parts[1], c.table, cell, index ) );
|
|
|
|
val = parseNumber( format( data.iFilter, c.table, cell, index ) );
|
2015-02-24 06:00:52 +00:00
|
|
|
if ( high < low ) {
|
|
|
|
// swap high & low
|
|
|
|
t = high; high = low; low = t;
|
|
|
|
}
|
|
|
|
return low <= val && val <= high;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
})(jQuery);
|