Skip to content

Commit fb13df3

Browse files
author
natinusala
committed
1 parent b0fd06d commit fb13df3

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ https://github.com/gregwebs/jquery-uitablefilter
33
##What's new ?
44
With this version the 'column' argument has been modified to be an array of columns instead of being just one column.
55
Consequently, the script is now able to search in several columns. If you want the original behaviour back, put an array with only one entry.
6-
If you don't want to create any filter, just put an emptyarray as argument.
6+
If you don't want to create any filter, just put an empty array as argument.
7+
##Download
8+
Download the latest version here : https://raw.github.com/natinusala/jquery-uitablefilter/master/jquery.uitablefilter.js
79
##Example
810
Here is an example (see the original project README for more informations). It will search the word 'Pepper' in #table in columns 'Price', 'Item' and 'ID'.
911
```

jquery.uitablefilter.js

Lines changed: 26 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,28 @@
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 && column.length != 0 )
37+
{
38+
var index = new Array();
39+
40+
for (var j = 0; j < column.length; j++)
41+
{
42+
jq.find("thead > tr:last > th").each(function(i) {
43+
if ($.trim($(this).text()) == column[j]) {
44+
index[j] = i;
45+
return false;
46+
}
47+
});
48+
}
4149

42-
getText = function(elem){ return $(elem.find(
43-
("td:eq(" + index + ")") )).text()
50+
getText = function(elem) {
51+
var selector = "";
52+
for (var i = 0; i < index.length; i++)
53+
{
54+
if (i != 0) {selector += ",";}
55+
selector += "td:eq(" + index[i] + ")";
56+
}
57+
return $(elem.find((selector))).text();
4458
}
4559
}
4660

@@ -88,4 +102,4 @@
88102
}
89103
return true;
90104
}
91-
}) (jQuery);
105+
}) (jQuery);

0 commit comments

Comments
 (0)