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
6
+ * Multi-columns fork by natinusala
7
7
*
8
8
* documentation at http://gregweber.info/projects/uitablefilter
9
9
* https://github.com/natinusala/jquery-uitablefilter
19
19
* optional arguments:
20
20
* array of columns to limit search too (the column title in the table header)
21
21
* ifHidden - callback to execute if one or more elements was hidden
22
+ * tdElem - specific element within <td> to be considered for searching or to limit search to,
23
+ * default:whole <td>. useful if <td> has more than one elements inside but want to
24
+ * limit search within only some of elements or only visible elements. eg tdElem can be "td span"
22
25
*/
23
26
( function ( $ ) {
24
- $ . uiTableFilter = function ( jq , phrase , column , ifHidden ) {
27
+ $ . uiTableFilter = function ( jq , phrase , column , ifHidden , tdElem ) {
28
+ if ( ! tdElem ) tdElem = "td" ;
25
29
var new_hidden = false ;
26
30
if ( this . last_phrase === phrase ) return false ;
27
31
33
37
var noMatch = function ( elem ) { elem . hide ( ) ; new_hidden = true }
34
38
var getText = function ( elem ) { return elem . text ( ) }
35
39
36
- if ( column )
40
+ if ( column )
37
41
{
38
42
if ( ! $ . isArray ( column ) )
39
43
{
40
44
column = new Array ( column ) ;
41
45
}
42
-
43
- var index = new Array ( ) ;
44
-
45
- jq . find ( "thead > tr:last > th" ) . each ( function ( i )
46
+
47
+ var index = new Array ( ) ;
48
+
49
+ jq . find ( "thead > tr:last > th" ) . each ( function ( i )
46
50
{
47
51
for ( var j = 0 ; j < column . length ; j ++ )
48
- {
52
+ {
49
53
if ( $ . trim ( $ ( this ) . text ( ) ) == column [ j ] )
50
54
{
51
55
index [ j ] = i ;
52
56
break ;
53
- }
57
+ }
54
58
}
55
59
56
60
} ) ;
57
-
61
+
58
62
getText = function ( elem ) {
59
63
var selector = "" ;
60
64
for ( var i = 0 ; i < index . length ; i ++ )
61
65
{
62
66
if ( i != 0 ) { selector += "," ; }
63
- selector += "td :eq(" + index [ i ] + ")" ;
67
+ selector += tdElem + " :eq(" + index [ i ] + ")" ;
64
68
}
65
69
return $ ( elem . find ( ( selector ) ) ) . text ( ) ;
66
70
}
110
114
}
111
115
return true ;
112
116
}
113
- } ) ( jQuery ) ;
117
+ } ) ( jQuery ) ;
0 commit comments