forked from xdreamer/searchtablejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
65 lines (57 loc) · 2.1 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
SearchTable
version 0.1 alpha
22nd October 2010
Robert Henjes, http://www.rhenjes.de
22 Okt 2010
Code partly copied from: http://www.vonloesch.de/node/23
Thanks to many, many people for contributions and suggestions.
*/
searchtable = {
filtersingle: function(term, _id, cellNr) {
var suche = term.value.toLowerCase();
var table = searchtable.getTableByID(_id);
var ele;
for (var r = 1; r < table.rows.length; r++){
ele = table.rows[r].cells[cellNr].innerHTML.replace(/<[^>]+>/g,"");
if (ele.toLowerCase().indexOf(suche)>=0 )
table.rows[r].style.display = '';
else table.rows[r].style.display = 'none';
}
},
filterwords: function(phrase, _id) {
var words = phrase.value.toLowerCase().split(" ");
var table = searchtable.getTableByID(_id);
var ele;
for (var r = 1; r < table.rows.length; r++){
ele = table.rows[r].innerHTML.replace(/<[^>]+>/g,"");
var displayStyle = 'none';
for (var i = 0; i < words.length; i++) {
if (ele.toLowerCase().indexOf(words[i])>=0)
displayStyle = '';
else {
displayStyle = 'none';
break;
}
}
table.rows[r].style.display = displayStyle;
}
},
filterall: function(term, _id) {
var searchstr = term.value.toLowerCase();
var table = searchtable.getTableByID(_id);
var ele;
for (var r = 1; r < table.rows.length; r++){
ele = table.rows[r].innerHTML.replace(/<[^>]+>/g,"");
var displayStyle = 'none';
if (ele.toLowerCase().indexOf(searchstr)>=0)
displayStyle = '';
else displayStyle = 'none';
table.rows[r].style.display = displayStyle;
}
},
getTableByID: function(_id) {
var _table = document.getElementById(_id).getElementsByTagName('table')[0];
return _table;
},
};