browser: avoid exceptional colgroup filter offset
[sheet.git] / searchlocal.js
index 5d7493b100616134bddd693d6cdef245010b2974..8c33f8d0f0c5bb1451d34af494dd9f8e82c90c8b 100644 (file)
@@ -1,3 +1,5 @@
+var filterupdate;
+
 function filtercell(el, set, action) {
        switch (action) {
                case 'focus':
@@ -36,7 +38,7 @@ function filtercols(table, match, action) {
                                if (match(cell)) {
                                        if (!matchloc) matchloc = [loc];
                                        matchloc[1] = loc + cell.colSpan;
-                                       filtercell(table.children.item(x+2), true, action); // colgroup
+                                       filtercell(table.children.item(x), true, action); // colgroup
                                }
                        }
                        var keep = matchloc && loc >= matchloc[0] && loc < matchloc[1];
@@ -54,6 +56,8 @@ function filterrows(table, match, action) {
 }
 
 function filtertable(query, action) {
+       filterupdate = undefined;
+       if (query === undefined) query = document.getElementById('search').q.value;
        var table = document.getElementsByTagName('TABLE')[0];
 
        if (!action) {
@@ -128,7 +132,8 @@ function prependsearch(target) {
                        newelement('input', {
                                type: 'search',
                                name: 'q',
-                               onkeyup: "filtertable(this.value, 'focus')",
+                               onkeyup: "if (!filterupdate) filterupdate = "
+                                       + "window.setTimeout(filtertable, 300, undefined, 'focus')",
                        }),
                        newelement('input', {
                                type: 'button',