Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow applying repeated filters and then clearing them #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions addons/pager/jquery.tablesorter.pager.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,17 @@

renderTable(table,rows);
};


this.jumpToPage = function() {
return this.each(function() {
var c = this.config;
var pageinfo = $(c.cssPageDisplay,c.container).val();
c.page = parseInt(pageinfo.substr(0, pageinfo.indexOf(c.seperator))) - 1;
moveToPage(this);
return false;
})
};

this.defaults = {
size: 10,
offset: 0,
Expand Down Expand Up @@ -173,12 +183,12 @@
});
});
};

}
});
// extend plugin scope
$.fn.extend({
tablesorterPager: $.tablesorterPager.construct
tablesorterPager: $.tablesorterPager.construct,
tablesorterPagerjump: $.tablesorterPager.jumpToPage
});

})(jQuery);
44 changes: 42 additions & 2 deletions jquery.tablesorter.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,13 +689,35 @@

function getCachedSortType(parsers, i) {
return parsers[i].type;
}; /* public methods */
};

function filterTable(table, cache, filter) {
if (table.config.debug) {
var sortTime = new Date();
}
var filteredCache = {
row: cache.row,
normalized: []
};
for(var i = 0; i < cache.normalized.length; i++) {
var o = cache.normalized[i];
if(filter(o)) {
filteredCache.normalized.push(o);
}
}
if (table.config.debug) {
benchmark("Search table using " + filter + " time:", sortTime);
}
return filteredCache;
}

/* public methods */
this.construct = function (settings) {
return this.each(function () {
// if no thead or tbody quit.
if (!this.tHead || !this.tBodies) return;
// declare
var $this, $document, $headers, cache, config, shiftDown = 0,
var $this, $document, $headers, cache, config, origCache = null, shiftDown = 0,
sortOrder;
// new blank config object
this.config = {};
Expand Down Expand Up @@ -825,6 +847,24 @@
}).bind("applyWidgets", function () {
// apply widgets
applyWidget(this);
}).bind("filter", function(e, filter){
var filteredCache = filterTable(this, cache, filter);
if(origCache == null) {
origCache = {
row: [],
normalized: []
};
origCache.row = cache.row;
origCache.normalized = cache.normalized;
}
cache.normalized = filteredCache.normalized;
appendToTable(this, cache);
}).bind("clearFilters", function() {
if(origCache != null) {
cache = origCache;
origCache = null;
appendToTable(this, cache);
}
});
if ($.metadata && ($(this).metadata() && $(this).metadata().sortlist)) {
config.sortList = $(this).metadata().sortlist;
Expand Down