mirror of
https://github.com/Mottie/tablesorter.git
synced 2025-01-12 15:24:21 +00:00
fix filter + ajax issue #270 & added public filter get & set functions
This commit is contained in:
parent
7333519717
commit
10426559dc
@ -322,11 +322,7 @@ ts.addWidget({
|
|||||||
// dig fer gold
|
// dig fer gold
|
||||||
checkFilters = function(filter){
|
checkFilters = function(filter){
|
||||||
var arry = $.isArray(filter),
|
var arry = $.isArray(filter),
|
||||||
v = (arry) ? filter : c.$filters.map(function(t){
|
v = (arry) ? filter : ts.getFilters(table),
|
||||||
// make sure input arry index matches header indexes.
|
|
||||||
t = $(this).find('select.' + css + ', input.' + css);
|
|
||||||
return t.length ? t.val() || '' : '';
|
|
||||||
}).get(),
|
|
||||||
cv = (v || []).join(''); // combined filter values
|
cv = (v || []).join(''); // combined filter values
|
||||||
// add filter array back into inputs
|
// add filter array back into inputs
|
||||||
if (arry) {
|
if (arry) {
|
||||||
@ -464,7 +460,7 @@ ts.addWidget({
|
|||||||
}
|
}
|
||||||
|
|
||||||
last = cv; // save last search
|
last = cv; // save last search
|
||||||
$t.data('lastSearch', last);
|
$t.data('lastSearch', v);
|
||||||
if (c.debug){
|
if (c.debug){
|
||||||
ts.benchmark("Completed filter widget search", time);
|
ts.benchmark("Completed filter widget search", time);
|
||||||
}
|
}
|
||||||
@ -580,7 +576,7 @@ ts.addWidget({
|
|||||||
$t.find('.' + css).val('');
|
$t.find('.' + css).val('');
|
||||||
}
|
}
|
||||||
// send false argument to force a new search; otherwise if the filter hasn't changed, it will return
|
// send false argument to force a new search; otherwise if the filter hasn't changed, it will return
|
||||||
filter = e.type === 'search' ? filter : e.type === 'updateComplete' ? $t.data('lastSearch') : false;
|
filter = e.type === 'search' ? filter : e.type === 'updateComplete' ? $t.data('lastSearch') : '';
|
||||||
checkFilters(filter);
|
checkFilters(filter);
|
||||||
return false;
|
return false;
|
||||||
})
|
})
|
||||||
@ -588,15 +584,16 @@ ts.addWidget({
|
|||||||
// ignore arrow and meta keys; allow backspace
|
// ignore arrow and meta keys; allow backspace
|
||||||
if (e.type === 'keyup' && ((e.which < 32 && e.which !== 8) || (e.which >= 37 && e.which <=40) || (e.which !== 13 && !wo.filter_liveSearch))) { return; }
|
if (e.type === 'keyup' && ((e.which < 32 && e.which !== 8) || (e.which >= 37 && e.which <=40) || (e.which !== 13 && !wo.filter_liveSearch))) { return; }
|
||||||
// skip delay
|
// skip delay
|
||||||
if (typeof filter !== 'undefined' && filter !== true){
|
if (typeof filter === 'undefined' || filter === false){
|
||||||
checkFilters(filter);
|
checkFilters();
|
||||||
|
} else {
|
||||||
|
// delay filtering
|
||||||
|
clearTimeout(timer);
|
||||||
|
timer = setTimeout(function(){
|
||||||
|
checkFilters(filter);
|
||||||
|
}, wo.filter_searchDelay);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
// delay filtering
|
|
||||||
clearTimeout(timer);
|
|
||||||
timer = setTimeout(function(){
|
|
||||||
checkFilters(false);
|
|
||||||
}, wo.filter_searchDelay);
|
|
||||||
return false;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// parse columns after formatter, in case the class is added at that point
|
// parse columns after formatter, in case the class is added at that point
|
||||||
@ -635,8 +632,8 @@ ts.addWidget({
|
|||||||
// it would append the same options twice.
|
// it would append the same options twice.
|
||||||
buildDefault(true);
|
buildDefault(true);
|
||||||
|
|
||||||
$t.find('select.' + css).bind('change search', function(){
|
$t.find('select.' + css).bind('change search', function(e, filter){
|
||||||
checkFilters();
|
checkFilters(filter);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (wo.filter_hideFilters){
|
if (wo.filter_hideFilters){
|
||||||
@ -714,6 +711,21 @@ ts.addWidget({
|
|||||||
if (wo.filterreset) { $(wo.filter_reset).unbind('click.tsfilter'); }
|
if (wo.filterreset) { $(wo.filter_reset).unbind('click.tsfilter'); }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
ts.getFilters = function(table) {
|
||||||
|
var c = table ? $(table)[0].config : {};
|
||||||
|
return c && c.$filters ? c.$filters.find('.' + c.widgetOptions.filter_cssFilter).map(function(i, el) {
|
||||||
|
return $(el).val();
|
||||||
|
}).get() || [] : false;
|
||||||
|
};
|
||||||
|
ts.setFilters = function(table, filter, apply) {
|
||||||
|
var $t = $(table),
|
||||||
|
c = $t.length ? $t[0].config : {},
|
||||||
|
valid = c && c.$filters ? c.$filters.find('.' + c.widgetOptions.filter_cssFilter).each(function(i, el) {
|
||||||
|
$(el).val(filter[i] || '');
|
||||||
|
}) || false : false;
|
||||||
|
if (valid && apply) { $t.trigger('search'); }
|
||||||
|
return !!valid;
|
||||||
|
};
|
||||||
|
|
||||||
// Widget: Sticky headers
|
// Widget: Sticky headers
|
||||||
// based on this awesome article:
|
// based on this awesome article:
|
||||||
|
Loading…
Reference in New Issue
Block a user