3
3
* Dual licensed under the MIT and GPLv2 licenses just as jQuery is:
4
4
* http://jquery.org/license
5
5
*
6
+ * Multi-columns fork by natinusala
7
+ *
6
8
* documentation at http://gregweber.info/projects/uitablefilter
9
+ * https://github.com/natinusala/jquery-uitablefilter
7
10
*
8
11
* allows table rows to be filtered (made invisible)
9
12
* <code>
14
17
* jQuery object containing table rows
15
18
* phrase to search for
16
19
* 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)
18
21
* ifHidden - callback to execute if one or more elements was hidden
19
22
*/
20
23
( function ( $ ) {
30
33
var noMatch = function ( elem ) { elem . hide ( ) ; new_hidden = true }
31
34
var getText = function ( elem ) { return elem . text ( ) }
32
35
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
+ }
41
55
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 ( ) ;
44
66
}
45
67
}
46
68
88
110
}
89
111
return true ;
90
112
}
91
- } ) ( jQuery ) ;
113
+ } ) ( jQuery ) ;
0 commit comments