From f78dc440b42d95ce9caed1d087174dd4359982d6 Mon Sep 17 00:00:00 2001 From: ruiz107 Date: Tue, 28 Jun 2011 09:02:30 -0700 Subject: [PATCH] Just added a totalResults option to get the number of matches --- jquery.quicksearch.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/jquery.quicksearch.js b/jquery.quicksearch.js index 7bd6f65..8f7dbac 100644 --- a/jquery.quicksearch.js +++ b/jquery.quicksearch.js @@ -7,6 +7,7 @@ stripeRows: null, loader: null, noResults: '', + totalResults: '', bind: 'keyup', onBefore: function () { return; @@ -35,7 +36,8 @@ this.go = function () { - var i = 0, + var i = 0, + numMatchedRows = 0, noresults = true, query = options.prepareQuery(val), val_empty = (val.replace(' ', '').length === 0); @@ -44,15 +46,16 @@ if (val_empty || options.testQuery(query, cache[i], rowcache[i])) { options.show.apply(rowcache[i]); noresults = false; + numMatchedRows++; } else { options.hide.apply(rowcache[i]); } } if (noresults) { - this.results(false); + this.results(false, numMatchedRows); } else { - this.results(true); + this.results(true, numMatchedRows); this.stripe(); } @@ -83,7 +86,7 @@ return output; }; - this.results = function (bool) { + this.results = function (bool, numMatchedRows) { if (typeof options.noResults === "string" && options.noResults !== "") { if (bool) { $(options.noResults).hide(); @@ -91,6 +94,10 @@ $(options.noResults).show(); } } + + if (typeof options.totalResults === "string" && options.totalResults !== "") { + $(options.totalResults).html(numMatchedRows); + } return this; };