3 /* set or clear the ' invisibleRow' in the tr's classname, according to visible */
4 function plc_table_row_visible (row,visible) {
7 cn=cn.replace(" invisibleRow","");
8 if (! visible) cn += " invisibleRow";
12 /* maintain the number of matching entries in the <tbody> element's classname */
13 function plc_table_tbody_matching (tbody, matching) {
14 var new_cn="matching-" + matching;
15 var cn=tbody.className;
16 if (cn.match("matching-")) {
17 cn=cn.replace(/matching-\d+/,new_cn);
21 cn=cn.replace(/^ +/,"");
25 /* scan the table, and mark as visible
26 the rows that match (either AND or OR the patterns) */
27 function plc_table_filter (table_id,pattern_id,and_id) {
28 var tbody = document.getElementById(table_id).getElementsByTagName("tbody")[0];
30 var pattern_area = document.getElementById(pattern_id);
31 var pattern_text = pattern_area.value;
32 var row_index, row, cells, cell_index, cell, visible;
34 var matching_entries=0;
35 var and_button=document.getElementById(and_id);
36 var and_if_true=and_button.checked;
39 // remove whitespaces at the beginning and end
40 pattern_text = pattern_text.replace(/[ \t]+$/,"");
41 pattern_text = pattern_text.replace(/^[ \t]+/,"");
43 if (pattern_text.indexOf ("&") != -1) {
44 pattern_text = pattern_text.replace(/&$/,"").replace(/&/," ");
45 pattern_area.value=pattern_text;
46 and_button.checked=true;
48 } else if (pattern_text.indexOf ("|") != -1 ) {
49 pattern_text = pattern_text.replace(/\|$/,"").replace(/\|/," ");
50 pattern_area.value=pattern_text;
51 and_button.checked=false;
55 var patterns = pattern_text.split(" ");
57 for (row_index = 0; row=rows[row_index]; row_index++) {
61 if (patterns.length == 0) {
63 } else if (and_if_true) {
64 /* AND mode: all patterns must match */
67 var pattern_matched=false;
69 for (cell_index = 0; cell=cells[cell_index]; cell_index++) {
70 if ( cell.innerHTML.match(pattern)) pattern_matched=true;
72 if ( ! pattern_matched ) visible=false;
75 /* OR mode: any match is good enough */
77 for (cell_index = 0; cell=cells[cell_index]; cell_index++) {
80 if (cell.innerHTML.match(pattern)) visible=true;
84 plc_table_row_visible(row,visible);
85 if (visible) matching_entries +=1;
87 plc_table_tbody_matching(tbody,matching_entries);
88 tablePaginater.init(table_id);
91 function plc_table_filter_reset (table_id, pattern_id) {
93 document.getElementById(pattern_id).value="";
94 plc_table_filter (table_id, pattern_id);