Skip to content

Commit 61b5d18

Browse files
committed
temporary (dirty) fix for filtering
proper fix will need to rewrite the table
1 parent 2cf61cb commit 61b5d18

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

docs/summary-table.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,26 @@ function table(data, options = {}) {
7979
requestAnimationFrame(() => {
8080
for (const s of summaries.filter(({type}) => type)) summary(s);
8181
});
82+
83+
// save table headers for the dirty copy below
84+
const thtype = [...d3.select(table).selectAll("th :nth-child(2)")]
85+
const thsummary = [...d3.select(table).selectAll("th :nth-child(3)")]
8286
return container;
8387

8488
function refresh() {
8589
const index0 = d3.range(data.length ?? data.numRows);
8690
let index = index0;
8791
for (const [, f] of filters) index = index.filter(f);
88-
table.replaceWith(table = _Inputs.table(index === index0 ? data : take(data, index), options))
92+
93+
// TODO: make a fork of Inputs.table that works with index
94+
// In the meantime, here's a very dirty approach
95+
const _data = index === index0 ? data : take(data, index);
96+
table.replaceWith(table = _Inputs.table(_data, options));
97+
const th = d3.select(table).selectAll("th");
98+
th.append((d, i) => thtype[i]);
99+
th.append((d, i) => thsummary[i]);
89100
}
101+
90102
function take(data, index) {
91103
return Array.from(index, (i) => data.get(i));
92104
}
@@ -97,7 +109,8 @@ function table(data, options = {}) {
97109
if (value) {
98110
try {
99111
const re = new RegExp(`(^|\b)${value}`, "ui");
100-
filters.set("search", (i) => textFields.some(({values}) => re.test(values.get(i))));
112+
let tmp;
113+
filters.set("search", (i) => textFields.some(({values}) => ((tmp = values.get(i)) && re.test(tmp))));
101114
} catch(error) {
102115
console.warn(error);
103116
}

0 commit comments

Comments
 (0)