From e403b269e865b63f1735b97e096599809be6aec9 Mon Sep 17 00:00:00 2001 From: Toby Allen Date: Sat, 19 Mar 2016 08:51:08 +0000 Subject: [PATCH 1/8] Moved Matching of text to a function. Added matching of data attribute for extra filtering. --- jquery.filtertable.js | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/jquery.filtertable.js b/jquery.filtertable.js index cbaaa0a..97e3f10 100644 --- a/jquery.filtertable.js +++ b/jquery.filtertable.js @@ -35,7 +35,8 @@ return function(a) { var found = false; $.each(args, function(j, v) { - if ($(a).text().toUpperCase().indexOf(v.toUpperCase()) >= 0) { + // if ($(a).text().toUpperCase().indexOf(v.toUpperCase()) >= 0) { + if (isMatch(a,v)){ found = true; return false; } @@ -60,8 +61,10 @@ return function(a) { var found = 0; // how many terms were found? $.each(args, function(j, v) { - if ($(a).text().toUpperCase().indexOf(v.toUpperCase()) >= 0) { + //if ($(a).text().toUpperCase().indexOf(v.toUpperCase()) >= 0) { + if (isMatch(a,v)) { found++; // found another term + } }); return found === args.length; // did we find all of them in this cell? @@ -70,7 +73,15 @@ } else { // build the pseudo selector for jQuery >= 1.8 $.expr[':'].filterTableFind = jQuery.expr.createPseudo(function(arg) { return function(el) { - return $(el).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0; + return isMatch(el,arg); + /* var res = $(el).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0; + if (res == false){ + if ($(el).data("filtertablekeywords") != undefined){ + + res = $(el).data("filtertablekeywords").toUpperCase().indexOf(arg.toUpperCase()) >= 0; + } + } + return res;*/ }; }); $.expr[':'].filterTableFindAny = jQuery.expr.createPseudo(function(arg) { @@ -90,10 +101,11 @@ return function(el) { var found = false; $.each(args, function(i, v) { - if ($(el).text().toUpperCase().indexOf(v.toUpperCase()) >= 0) { + //if ($(el).text().toUpperCase().indexOf(v.toUpperCase()) >= 0) { + if(isMatch(el, v)){ found = true; return false; // short-circuit the searching since this cell has one of the terms - } + } }); return found; }; @@ -115,14 +127,26 @@ return function(el) { var found = 0; // how many terms were found? $.each(args, function(i, v) { - if ($(el).text().toUpperCase().indexOf(v.toUpperCase()) >= 0) { + //if ($(el).text().toUpperCase().indexOf(v.toUpperCase()) >= 0) { + if(isMatch(el,v)){ found++; // found another term + } }); return found === args.length; // did we find all of them in this cell? }; }); } + var isMatch = function(element, searchString){ + var result = $(element).text().toUpperCase().indexOf(searchString.toUpperCase()) >= 0; + if (result == false){ + if ($(element).data("filtertablekeywords") != undefined){ + + result = $(element).data("filtertablekeywords").toUpperCase().indexOf(searchString.toUpperCase()) >= 0; + } + } + return result; + } $.fn.filterTable = function(options) { // define the filterTable plugin var defaults = { // start off with some default settings autofocus: false, // make the filter input field autofocused (not recommended for accessibility) From 36ba061653b9acedbc0e7968dfdeafb63cada4b0 Mon Sep 17 00:00:00 2001 From: Toby Allen Date: Sat, 19 Mar 2016 09:39:32 +0000 Subject: [PATCH 2/8] Added Datatag example page Based on simple example with quick tags --- examples/filtertable-datatag.html | 88 +++++++++++++++++++++++++++++++ examples/index.html | 1 + 2 files changed, 89 insertions(+) create mode 100644 examples/filtertable-datatag.html diff --git a/examples/filtertable-datatag.html b/examples/filtertable-datatag.html new file mode 100644 index 0000000..be408d4 --- /dev/null +++ b/examples/filtertable-datatag.html @@ -0,0 +1,88 @@ + + + + + + jQuery.FilterTable Sample + + + + +

jQuery.FilterTable Sample

+

← More samples

+

This is a sample of the jQuery.FilterTable plugin. The filter searches both the text of the table and any additional keywords that are in the data-filterTableKeywords attribute.

+

Presidents of the United States of America and their party allegience

+
Information taken from wikipedia + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#PresidentTermsTenure
1George Washingtontwo1789-1797
2John Adamsone1797-1801
3Thomas Jeffersontwo1801-1809
4James Madisontwo1809-1817
5James Monroetwo1817-1825
6John Quincy Adamsone1825-1829
7Andrew Jacksontwo1829-1837
8Martin Van Burenone1837-1841
9William Henry Harrisonone-partial1841
10John Tylerone-partial1841-1845
11James Knox Polkone1845-1849
12Zachary Taylorone-partial1849-1850
13Millard Fillmoreone-partial1850-1853
14Franklin Pierceone1853-1857
15James Buchananone1857-1861
16Abraham Lincolntwo-partial1861-1865
17Andrew Johnsonone-partial1865-1869
18Ulysses S. Granttwo1869-1877
19Rutherford Birchard Hayesone1877-1881
20James Abram Garfieldone-partial1881
21Chester Alan Arthurone-partial1881-1885
22Grover Clevelandone1885-1889
23Benjamin Harrisonone1889-1893
24Grover Clevelandone-again1893-1897
25William McKinleytwo-partial1897-1901
26Theodore Roosevelttwo-partial1901-1909
27William Howard Taftone1909-1913
28Woodrow Wilsontwo1913-1921
29Warren Gamaliel Hardingtwo-partial1921-1923
30Calvin Coolidgetwo-partial1923-1929
31Herbert Clark Hooverone1929-1933
32Franklin Delano Rooseveltfour-partial1933-1945
33Harry S. Trumantwo-partial1945-1953
34Dwight David Eisenhowertwo1953-1961
35John Fitzgerald Kennedytwo-partial1961-1963
36Lyndon Baines Johnsontwo-partial1963-1969
37Richard Milhous Nixontwo-partial1969-1974
38Gerald Rudolph Fordtwo-partial1974-1977
39James Earl Carter, Jr.one1977-1981
40Ronald Wilson Reagantwo1981-1989
41George Herbert Walker Bushone1989-1993
42William Jefferson Clintontwo1993-2001
43George Walker Bushtwo2001-2009
44Barack Hussein Obamaone2009-
+

Data as of October, 2012.

+

Code

+
$('table').filterTable();
+ + + + + \ No newline at end of file diff --git a/examples/index.html b/examples/index.html index 9a22ead..f924411 100644 --- a/examples/index.html +++ b/examples/index.html @@ -13,6 +13,7 @@

jQuery.FilterTable Samples

  • Basic Sample
  • Alternate Row Striping
  • Quick List Items
  • +
  • Search Data tag value
  • Using an Existing Input for Filtering
  • Filter on Any Term
  • Filter on All Terms
  • From 0407bc2c43fa962554fd6cb7a8ae04df91c85c6d Mon Sep 17 00:00:00 2001 From: Toby Allen Date: Sat, 19 Mar 2016 09:43:04 +0000 Subject: [PATCH 3/8] Removed commented out lines. --- jquery.filtertable.js | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/jquery.filtertable.js b/jquery.filtertable.js index 97e3f10..f24bed2 100644 --- a/jquery.filtertable.js +++ b/jquery.filtertable.js @@ -35,7 +35,6 @@ return function(a) { var found = false; $.each(args, function(j, v) { - // if ($(a).text().toUpperCase().indexOf(v.toUpperCase()) >= 0) { if (isMatch(a,v)){ found = true; return false; @@ -61,7 +60,6 @@ return function(a) { var found = 0; // how many terms were found? $.each(args, function(j, v) { - //if ($(a).text().toUpperCase().indexOf(v.toUpperCase()) >= 0) { if (isMatch(a,v)) { found++; // found another term @@ -74,14 +72,6 @@ $.expr[':'].filterTableFind = jQuery.expr.createPseudo(function(arg) { return function(el) { return isMatch(el,arg); - /* var res = $(el).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0; - if (res == false){ - if ($(el).data("filtertablekeywords") != undefined){ - - res = $(el).data("filtertablekeywords").toUpperCase().indexOf(arg.toUpperCase()) >= 0; - } - } - return res;*/ }; }); $.expr[':'].filterTableFindAny = jQuery.expr.createPseudo(function(arg) { @@ -101,7 +91,6 @@ return function(el) { var found = false; $.each(args, function(i, v) { - //if ($(el).text().toUpperCase().indexOf(v.toUpperCase()) >= 0) { if(isMatch(el, v)){ found = true; return false; // short-circuit the searching since this cell has one of the terms @@ -127,7 +116,6 @@ return function(el) { var found = 0; // how many terms were found? $.each(args, function(i, v) { - //if ($(el).text().toUpperCase().indexOf(v.toUpperCase()) >= 0) { if(isMatch(el,v)){ found++; // found another term @@ -138,15 +126,15 @@ }); } var isMatch = function(element, searchString){ - var result = $(element).text().toUpperCase().indexOf(searchString.toUpperCase()) >= 0; - if (result == false){ - if ($(element).data("filtertablekeywords") != undefined){ - - result = $(element).data("filtertablekeywords").toUpperCase().indexOf(searchString.toUpperCase()) >= 0; - } - } - return result; + var result = $(element).text().toUpperCase().indexOf(searchString.toUpperCase()) >= 0; + if (result == false){ + if ($(element).data("filtertablekeywords") != undefined){ + result = $(element).data("filtertablekeywords").toUpperCase().indexOf(searchString.toUpperCase()) >= 0; + } + } + return result; } + $.fn.filterTable = function(options) { // define the filterTable plugin var defaults = { // start off with some default settings autofocus: false, // make the filter input field autofocused (not recommended for accessibility) From fdd9e8e51b093c9c2aa86b4fd9542f3167b4376b Mon Sep 17 00:00:00 2001 From: Toby Allen Date: Sun, 20 Mar 2016 18:36:00 +0000 Subject: [PATCH 4/8] minor update to example file for data attibute --- examples/filtertable-all-terms.html | 2 +- examples/filtertable-any-term.html | 2 +- examples/filtertable-datatag.html | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/filtertable-all-terms.html b/examples/filtertable-all-terms.html index bc460f0..9a1e8fd 100644 --- a/examples/filtertable-all-terms.html +++ b/examples/filtertable-all-terms.html @@ -85,7 +85,7 @@

    Code

    filterExpression: 'filterTableFindAll' }); - + - + - + - \ No newline at end of file + From f2a4cfeed425e8473866c09040e59c06c638f8ca Mon Sep 17 00:00:00 2001 From: Toby Allen Date: Sat, 23 Dec 2017 11:36:02 +0000 Subject: [PATCH 7/8] Update filtertable-any-term.html --- examples/filtertable-any-term.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/filtertable-any-term.html b/examples/filtertable-any-term.html index 5befecc..6b7dfaa 100644 --- a/examples/filtertable-any-term.html +++ b/examples/filtertable-any-term.html @@ -82,7 +82,7 @@

    Code

    filterExpression: 'filterTableFindAny' }); - + - \ No newline at end of file + From 9b8974687fa909bdef507be25ac0a836d7d4c693 Mon Sep 17 00:00:00 2001 From: toby allen Date: Sat, 5 Jan 2019 22:58:44 +0000 Subject: [PATCH 8/8] Added back in isMatch function that had gone missing from repo. --- jquery.filtertable.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/jquery.filtertable.js b/jquery.filtertable.js index 3e46957..40e0ae7 100644 --- a/jquery.filtertable.js +++ b/jquery.filtertable.js @@ -103,6 +103,8 @@ return found; }; }); + + $.expr[':'].filterTableFindAll = jQuery.expr.createPseudo(function (arg) { // build an array of each non-falsey value passed var raw_args = arg.split(/[\s,]/), @@ -130,6 +132,16 @@ }; }); } + + var isMatch = function(element, searchString){ + var result = $(element).text().toUpperCase().indexOf(searchString.toUpperCase()) >= 0; + if (result == false){ + if ($(element).data("filtertablekeywords") != undefined){ + result = $(element).data("filtertablekeywords").toUpperCase().indexOf(searchString.toUpperCase()) >= 0; + } + } + return result; + } // define the filterTable plugin $.fn.filterTable = function (options) { // start off with some default settings