Skip to content

Commit d5f4184

Browse files
committed
support searching multiple columns
column can take an Array
1 parent 6cb6d7a commit d5f4184

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

jquery.uitablefilter.js

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
* Dual licensed under the MIT and GPLv2 licenses just as jQuery is:
44
* http://jquery.org/license
55
*
6+
* Multi-columns fork by natinusala
7+
*
68
* documentation at http://gregweber.info/projects/uitablefilter
9+
* https://github.com/natinusala/jquery-uitablefilter
710
*
811
* allows table rows to be filtered (made invisible)
912
* <code>
@@ -14,7 +17,7 @@
1417
* jQuery object containing table rows
1518
* phrase to search for
1619
* optional arguments:
17-
* column to limit search too (the column title in the table header)
20+
* array of columns to limit search too (the column title in the table header)
1821
* ifHidden - callback to execute if one or more elements was hidden
1922
*/
2023
(function($) {
@@ -30,17 +33,36 @@
3033
var noMatch = function(elem) { elem.hide(); new_hidden = true }
3134
var getText = function(elem) { return elem.text() }
3235

33-
if( column ) {
34-
var index = null;
35-
jq.find("thead > tr:last > th").each( function(i){
36-
if( $.trim($(this).text()) == column ){
37-
index = i; return false;
38-
}
39-
});
40-
if( index == null ) throw("given column: " + column + " not found")
36+
if( column )
37+
{
38+
if (!$.isArray(column))
39+
{
40+
column = new Array(column);
41+
}
42+
43+
var index = new Array();
44+
45+
jq.find("thead > tr:last > th").each(function(i)
46+
{
47+
for (var j = 0; j < column.length; j++)
48+
{
49+
if ($.trim($(this).text()) == column[j])
50+
{
51+
index[j] = i;
52+
break;
53+
}
54+
}
4155

42-
getText = function(elem){ return $(elem.find(
43-
("td:eq(" + index + ")") )).text()
56+
});
57+
58+
getText = function(elem) {
59+
var selector = "";
60+
for (var i = 0; i < index.length; i++)
61+
{
62+
if (i != 0) {selector += ",";}
63+
selector += "td:eq(" + index[i] + ")";
64+
}
65+
return $(elem.find((selector))).text();
4466
}
4567
}
4668

@@ -88,4 +110,4 @@
88110
}
89111
return true;
90112
}
91-
}) (jQuery);
113+
}) (jQuery);

0 commit comments

Comments
 (0)