MCPcopy Create free account
hub / github.com/MADEVAL/Oat-Table / OtTable

Class OtTable

src/table.js:8–291  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6 }
7
8 class OtTable extends HTMLElement {
9 #controller;
10 #table;
11 #tbody;
12 #rows = [];
13 #headers = [];
14 #filter;
15 #status;
16 #selectedStatus;
17 #selectAll;
18 #emptyRow;
19
20 connectedCallback() {
21 this.#controller = new AbortController();
22 this.#init();
23 }
24
25 disconnectedCallback() {
26 this.#controller?.abort();
27 }
28
29 refresh() {
30 if (!this.#table) {
31 return;
32 }
33
34 this.#rows = Array.from(this.#tbody?.rows || []).filter(row => !row.hasAttribute('data-table-empty'));
35 this.#rows.forEach((row, index) => {
36 row.dataset.tableIndex = row.dataset.tableIndex || String(index);
37 });
38
39 this.#syncSelection();
40 this.#applyFilter(false);
41 }
42
43 #init() {
44 this.#table = this.querySelector('table');
45 this.#tbody = this.#table?.tBodies[0];
46
47 if (!this.#table || !this.#tbody) {
48 console.warn('ot-table: Missing table or tbody element');
49 return;
50 }
51
52 this.#filter = this.querySelector('[data-table-filter]');
53 this.#status = this.querySelector('[data-table-status]');
54 this.#selectedStatus = this.querySelector('[data-table-selected]');
55 this.#selectAll = this.querySelector('[data-table-select-all]');
56
57 this.#setupSort();
58 this.#setupFilter();
59 this.#setupSelection();
60 this.addEventListener('ot-table-refresh', () => this.refresh(), { signal: this.#controller.signal });
61
62 this.refresh();
63 this.#applyInitialSort();
64 }
65

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected