-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrowFilterer.js
More file actions
42 lines (41 loc) · 1.2 KB
/
rowFilterer.js
File metadata and controls
42 lines (41 loc) · 1.2 KB
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
/**
* A filter table rows.
*/
class rowFilterer {
addHideCondition(element) {
const parentRow = element.closest("tr");
if (!parentRow.hasOwnProperty("hideConditions")) {
parentRow.hideConditions = new Set();
}
parentRow.hideConditions.add(this.getElementColumnIndex(element));
rowFilterer.setHideStatus(parentRow);
}
removeHideCondition(element) {
const parentRow = element.closest("tr");
if (!parentRow.hasOwnProperty("hideConditions")) {
return;
}
parentRow.hideConditions.delete(this.getElementColumnIndex(element));
rowFilterer.setHideStatus(parentRow);
}
static setHideStatus(element) {
if (
element.hasOwnProperty("hideConditions") &&
element.hideConditions.size > 0
) {
element.style.display = "none";
// Automatically uncheck hidden checkboxes.
element
.querySelectorAll("input[type='checkbox']")
.forEach((checkbox) => (checkbox.checked = false));
} else {
element.style.display = "table-row";
}
}
getElementColumnIndex(element) {
const td = element.closest("td");
const tds = Array.from(td.closest("tr").children);
return tds.indexOf(td);
}
}
export { rowFilterer };