Skip to content

Commit 347a97c

Browse files
committed
Merge pull request #12 from smita786/master
allow to specify particular elements within <td> to limit search to
2 parents d5f4184 + 5f89361 commit 347a97c

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

jquery.uitablefilter.js

+16-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
6+
* Multi-columns fork by natinusala
77
*
88
* documentation at http://gregweber.info/projects/uitablefilter
99
* https://github.com/natinusala/jquery-uitablefilter
@@ -19,9 +19,13 @@
1919
* optional arguments:
2020
* array of columns to limit search too (the column title in the table header)
2121
* 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"
2225
*/
2326
(function($) {
24-
$.uiTableFilter = function(jq, phrase, column, ifHidden){
27+
$.uiTableFilter = function(jq, phrase, column, ifHidden, tdElem){
28+
if(!tdElem) tdElem = "td";
2529
var new_hidden = false;
2630
if( this.last_phrase === phrase ) return false;
2731

@@ -33,34 +37,34 @@
3337
var noMatch = function(elem) { elem.hide(); new_hidden = true }
3438
var getText = function(elem) { return elem.text() }
3539

36-
if( column )
40+
if( column )
3741
{
3842
if (!$.isArray(column))
3943
{
4044
column = new Array(column);
4145
}
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)
4650
{
4751
for (var j = 0; j < column.length; j++)
48-
{
52+
{
4953
if ($.trim($(this).text()) == column[j])
5054
{
5155
index[j] = i;
5256
break;
53-
}
57+
}
5458
}
5559

5660
});
57-
61+
5862
getText = function(elem) {
5963
var selector = "";
6064
for (var i = 0; i < index.length; i++)
6165
{
6266
if (i != 0) {selector += ",";}
63-
selector += "td:eq(" + index[i] + ")";
67+
selector += tdElem + ":eq(" + index[i] + ")";
6468
}
6569
return $(elem.find((selector))).text();
6670
}
@@ -110,4 +114,4 @@
110114
}
111115
return true;
112116
}
113-
}) (jQuery);
117+
}) (jQuery);

0 commit comments

Comments
 (0)