@@ -79,14 +79,26 @@ function table(data, options = {}) {
79
79
requestAnimationFrame (() => {
80
80
for (const s of summaries .filter (({type}) => type)) summary (s);
81
81
});
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)" )]
82
86
return container;
83
87
84
88
function refresh () {
85
89
const index0 = d3 .range (data .length ?? data .numRows );
86
90
let index = index0;
87
91
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]);
89
100
}
101
+
90
102
function take (data , index ) {
91
103
return Array .from (index, (i ) => data .get (i));
92
104
}
@@ -97,7 +109,8 @@ function table(data, options = {}) {
97
109
if (value) {
98
110
try {
99
111
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))));
101
114
} catch (error) {
102
115
console .warn (error);
103
116
}
0 commit comments