This commit is contained in:
parent
c06f71a5ad
commit
498ae6a12e
7 changed files with 98 additions and 21 deletions
|
|
@ -256,6 +256,10 @@ function dataTableScript(id) {
|
||||||
const rows = Array.from(tbody?.querySelectorAll("tr") || []);
|
const rows = Array.from(tbody?.querySelectorAll("tr") || []);
|
||||||
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
||||||
|
|
||||||
|
rows.forEach((row, index) => {
|
||||||
|
row.dataset.dataTableIndex = String(index);
|
||||||
|
});
|
||||||
|
|
||||||
function applyFilter() {
|
function applyFilter() {
|
||||||
const query = (input?.value || "").trim().toLowerCase();
|
const query = (input?.value || "").trim().toLowerCase();
|
||||||
let visible = 0;
|
let visible = 0;
|
||||||
|
|
@ -274,12 +278,18 @@ function dataTableScript(id) {
|
||||||
root.querySelectorAll("[data-data-table-sort]").forEach((button) => {
|
root.querySelectorAll("[data-data-table-sort]").forEach((button) => {
|
||||||
button.addEventListener("click", () => {
|
button.addEventListener("click", () => {
|
||||||
const column = button.dataset.dataTableSort;
|
const column = button.dataset.dataTableSort;
|
||||||
const current = button.getAttribute("aria-sort");
|
const previousColumn = root.dataset.dataTableSortColumn || "";
|
||||||
const direction = current === "ascending" ? "descending" : "ascending";
|
const previousDirection = root.dataset.dataTableSortDirection || "";
|
||||||
|
const direction =
|
||||||
|
previousColumn === column && previousDirection === "ascending"
|
||||||
|
? "descending"
|
||||||
|
: "ascending";
|
||||||
|
|
||||||
root.querySelectorAll("[data-data-table-sort]").forEach((other) => {
|
root.querySelectorAll("[data-data-table-sort]").forEach((other) => {
|
||||||
other.removeAttribute("aria-sort");
|
other.removeAttribute("aria-sort");
|
||||||
});
|
});
|
||||||
|
root.dataset.dataTableSortColumn = column;
|
||||||
|
root.dataset.dataTableSortDirection = direction;
|
||||||
button.setAttribute("aria-sort", direction);
|
button.setAttribute("aria-sort", direction);
|
||||||
|
|
||||||
rows
|
rows
|
||||||
|
|
@ -288,7 +298,8 @@ function dataTableScript(id) {
|
||||||
const leftValue = left.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
const leftValue = left.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
||||||
const rightValue = right.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
const rightValue = right.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
||||||
const result = collator.compare(leftValue, rightValue);
|
const result = collator.compare(leftValue, rightValue);
|
||||||
return direction === "ascending" ? result : -result;
|
if (result !== 0) return direction === "ascending" ? result : -result;
|
||||||
|
return Number(left.dataset.dataTableIndex || 0) - Number(right.dataset.dataTableIndex || 0);
|
||||||
})
|
})
|
||||||
.forEach((row) => tbody.appendChild(row));
|
.forEach((row) => tbody.appendChild(row));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -256,6 +256,10 @@ function dataTableScript(id) {
|
||||||
const rows = Array.from(tbody?.querySelectorAll("tr") || []);
|
const rows = Array.from(tbody?.querySelectorAll("tr") || []);
|
||||||
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
||||||
|
|
||||||
|
rows.forEach((row, index) => {
|
||||||
|
row.dataset.dataTableIndex = String(index);
|
||||||
|
});
|
||||||
|
|
||||||
function applyFilter() {
|
function applyFilter() {
|
||||||
const query = (input?.value || "").trim().toLowerCase();
|
const query = (input?.value || "").trim().toLowerCase();
|
||||||
let visible = 0;
|
let visible = 0;
|
||||||
|
|
@ -274,12 +278,18 @@ function dataTableScript(id) {
|
||||||
root.querySelectorAll("[data-data-table-sort]").forEach((button) => {
|
root.querySelectorAll("[data-data-table-sort]").forEach((button) => {
|
||||||
button.addEventListener("click", () => {
|
button.addEventListener("click", () => {
|
||||||
const column = button.dataset.dataTableSort;
|
const column = button.dataset.dataTableSort;
|
||||||
const current = button.getAttribute("aria-sort");
|
const previousColumn = root.dataset.dataTableSortColumn || "";
|
||||||
const direction = current === "ascending" ? "descending" : "ascending";
|
const previousDirection = root.dataset.dataTableSortDirection || "";
|
||||||
|
const direction =
|
||||||
|
previousColumn === column && previousDirection === "ascending"
|
||||||
|
? "descending"
|
||||||
|
: "ascending";
|
||||||
|
|
||||||
root.querySelectorAll("[data-data-table-sort]").forEach((other) => {
|
root.querySelectorAll("[data-data-table-sort]").forEach((other) => {
|
||||||
other.removeAttribute("aria-sort");
|
other.removeAttribute("aria-sort");
|
||||||
});
|
});
|
||||||
|
root.dataset.dataTableSortColumn = column;
|
||||||
|
root.dataset.dataTableSortDirection = direction;
|
||||||
button.setAttribute("aria-sort", direction);
|
button.setAttribute("aria-sort", direction);
|
||||||
|
|
||||||
rows
|
rows
|
||||||
|
|
@ -288,7 +298,8 @@ function dataTableScript(id) {
|
||||||
const leftValue = left.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
const leftValue = left.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
||||||
const rightValue = right.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
const rightValue = right.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
||||||
const result = collator.compare(leftValue, rightValue);
|
const result = collator.compare(leftValue, rightValue);
|
||||||
return direction === "ascending" ? result : -result;
|
if (result !== 0) return direction === "ascending" ? result : -result;
|
||||||
|
return Number(left.dataset.dataTableIndex || 0) - Number(right.dataset.dataTableIndex || 0);
|
||||||
})
|
})
|
||||||
.forEach((row) => tbody.appendChild(row));
|
.forEach((row) => tbody.appendChild(row));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -256,6 +256,10 @@ function dataTableScript(id) {
|
||||||
const rows = Array.from(tbody?.querySelectorAll("tr") || []);
|
const rows = Array.from(tbody?.querySelectorAll("tr") || []);
|
||||||
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
||||||
|
|
||||||
|
rows.forEach((row, index) => {
|
||||||
|
row.dataset.dataTableIndex = String(index);
|
||||||
|
});
|
||||||
|
|
||||||
function applyFilter() {
|
function applyFilter() {
|
||||||
const query = (input?.value || "").trim().toLowerCase();
|
const query = (input?.value || "").trim().toLowerCase();
|
||||||
let visible = 0;
|
let visible = 0;
|
||||||
|
|
@ -274,12 +278,18 @@ function dataTableScript(id) {
|
||||||
root.querySelectorAll("[data-data-table-sort]").forEach((button) => {
|
root.querySelectorAll("[data-data-table-sort]").forEach((button) => {
|
||||||
button.addEventListener("click", () => {
|
button.addEventListener("click", () => {
|
||||||
const column = button.dataset.dataTableSort;
|
const column = button.dataset.dataTableSort;
|
||||||
const current = button.getAttribute("aria-sort");
|
const previousColumn = root.dataset.dataTableSortColumn || "";
|
||||||
const direction = current === "ascending" ? "descending" : "ascending";
|
const previousDirection = root.dataset.dataTableSortDirection || "";
|
||||||
|
const direction =
|
||||||
|
previousColumn === column && previousDirection === "ascending"
|
||||||
|
? "descending"
|
||||||
|
: "ascending";
|
||||||
|
|
||||||
root.querySelectorAll("[data-data-table-sort]").forEach((other) => {
|
root.querySelectorAll("[data-data-table-sort]").forEach((other) => {
|
||||||
other.removeAttribute("aria-sort");
|
other.removeAttribute("aria-sort");
|
||||||
});
|
});
|
||||||
|
root.dataset.dataTableSortColumn = column;
|
||||||
|
root.dataset.dataTableSortDirection = direction;
|
||||||
button.setAttribute("aria-sort", direction);
|
button.setAttribute("aria-sort", direction);
|
||||||
|
|
||||||
rows
|
rows
|
||||||
|
|
@ -288,7 +298,8 @@ function dataTableScript(id) {
|
||||||
const leftValue = left.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
const leftValue = left.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
||||||
const rightValue = right.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
const rightValue = right.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
||||||
const result = collator.compare(leftValue, rightValue);
|
const result = collator.compare(leftValue, rightValue);
|
||||||
return direction === "ascending" ? result : -result;
|
if (result !== 0) return direction === "ascending" ? result : -result;
|
||||||
|
return Number(left.dataset.dataTableIndex || 0) - Number(right.dataset.dataTableIndex || 0);
|
||||||
})
|
})
|
||||||
.forEach((row) => tbody.appendChild(row));
|
.forEach((row) => tbody.appendChild(row));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -256,6 +256,10 @@ function dataTableScript(id) {
|
||||||
const rows = Array.from(tbody?.querySelectorAll("tr") || []);
|
const rows = Array.from(tbody?.querySelectorAll("tr") || []);
|
||||||
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
||||||
|
|
||||||
|
rows.forEach((row, index) => {
|
||||||
|
row.dataset.dataTableIndex = String(index);
|
||||||
|
});
|
||||||
|
|
||||||
function applyFilter() {
|
function applyFilter() {
|
||||||
const query = (input?.value || "").trim().toLowerCase();
|
const query = (input?.value || "").trim().toLowerCase();
|
||||||
let visible = 0;
|
let visible = 0;
|
||||||
|
|
@ -274,12 +278,18 @@ function dataTableScript(id) {
|
||||||
root.querySelectorAll("[data-data-table-sort]").forEach((button) => {
|
root.querySelectorAll("[data-data-table-sort]").forEach((button) => {
|
||||||
button.addEventListener("click", () => {
|
button.addEventListener("click", () => {
|
||||||
const column = button.dataset.dataTableSort;
|
const column = button.dataset.dataTableSort;
|
||||||
const current = button.getAttribute("aria-sort");
|
const previousColumn = root.dataset.dataTableSortColumn || "";
|
||||||
const direction = current === "ascending" ? "descending" : "ascending";
|
const previousDirection = root.dataset.dataTableSortDirection || "";
|
||||||
|
const direction =
|
||||||
|
previousColumn === column && previousDirection === "ascending"
|
||||||
|
? "descending"
|
||||||
|
: "ascending";
|
||||||
|
|
||||||
root.querySelectorAll("[data-data-table-sort]").forEach((other) => {
|
root.querySelectorAll("[data-data-table-sort]").forEach((other) => {
|
||||||
other.removeAttribute("aria-sort");
|
other.removeAttribute("aria-sort");
|
||||||
});
|
});
|
||||||
|
root.dataset.dataTableSortColumn = column;
|
||||||
|
root.dataset.dataTableSortDirection = direction;
|
||||||
button.setAttribute("aria-sort", direction);
|
button.setAttribute("aria-sort", direction);
|
||||||
|
|
||||||
rows
|
rows
|
||||||
|
|
@ -288,7 +298,8 @@ function dataTableScript(id) {
|
||||||
const leftValue = left.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
const leftValue = left.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
||||||
const rightValue = right.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
const rightValue = right.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
||||||
const result = collator.compare(leftValue, rightValue);
|
const result = collator.compare(leftValue, rightValue);
|
||||||
return direction === "ascending" ? result : -result;
|
if (result !== 0) return direction === "ascending" ? result : -result;
|
||||||
|
return Number(left.dataset.dataTableIndex || 0) - Number(right.dataset.dataTableIndex || 0);
|
||||||
})
|
})
|
||||||
.forEach((row) => tbody.appendChild(row));
|
.forEach((row) => tbody.appendChild(row));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -256,6 +256,10 @@ function dataTableScript(id) {
|
||||||
const rows = Array.from(tbody?.querySelectorAll("tr") || []);
|
const rows = Array.from(tbody?.querySelectorAll("tr") || []);
|
||||||
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
||||||
|
|
||||||
|
rows.forEach((row, index) => {
|
||||||
|
row.dataset.dataTableIndex = String(index);
|
||||||
|
});
|
||||||
|
|
||||||
function applyFilter() {
|
function applyFilter() {
|
||||||
const query = (input?.value || "").trim().toLowerCase();
|
const query = (input?.value || "").trim().toLowerCase();
|
||||||
let visible = 0;
|
let visible = 0;
|
||||||
|
|
@ -274,12 +278,18 @@ function dataTableScript(id) {
|
||||||
root.querySelectorAll("[data-data-table-sort]").forEach((button) => {
|
root.querySelectorAll("[data-data-table-sort]").forEach((button) => {
|
||||||
button.addEventListener("click", () => {
|
button.addEventListener("click", () => {
|
||||||
const column = button.dataset.dataTableSort;
|
const column = button.dataset.dataTableSort;
|
||||||
const current = button.getAttribute("aria-sort");
|
const previousColumn = root.dataset.dataTableSortColumn || "";
|
||||||
const direction = current === "ascending" ? "descending" : "ascending";
|
const previousDirection = root.dataset.dataTableSortDirection || "";
|
||||||
|
const direction =
|
||||||
|
previousColumn === column && previousDirection === "ascending"
|
||||||
|
? "descending"
|
||||||
|
: "ascending";
|
||||||
|
|
||||||
root.querySelectorAll("[data-data-table-sort]").forEach((other) => {
|
root.querySelectorAll("[data-data-table-sort]").forEach((other) => {
|
||||||
other.removeAttribute("aria-sort");
|
other.removeAttribute("aria-sort");
|
||||||
});
|
});
|
||||||
|
root.dataset.dataTableSortColumn = column;
|
||||||
|
root.dataset.dataTableSortDirection = direction;
|
||||||
button.setAttribute("aria-sort", direction);
|
button.setAttribute("aria-sort", direction);
|
||||||
|
|
||||||
rows
|
rows
|
||||||
|
|
@ -288,7 +298,8 @@ function dataTableScript(id) {
|
||||||
const leftValue = left.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
const leftValue = left.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
||||||
const rightValue = right.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
const rightValue = right.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
||||||
const result = collator.compare(leftValue, rightValue);
|
const result = collator.compare(leftValue, rightValue);
|
||||||
return direction === "ascending" ? result : -result;
|
if (result !== 0) return direction === "ascending" ? result : -result;
|
||||||
|
return Number(left.dataset.dataTableIndex || 0) - Number(right.dataset.dataTableIndex || 0);
|
||||||
})
|
})
|
||||||
.forEach((row) => tbody.appendChild(row));
|
.forEach((row) => tbody.appendChild(row));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -256,6 +256,10 @@ function dataTableScript(id) {
|
||||||
const rows = Array.from(tbody?.querySelectorAll("tr") || []);
|
const rows = Array.from(tbody?.querySelectorAll("tr") || []);
|
||||||
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
||||||
|
|
||||||
|
rows.forEach((row, index) => {
|
||||||
|
row.dataset.dataTableIndex = String(index);
|
||||||
|
});
|
||||||
|
|
||||||
function applyFilter() {
|
function applyFilter() {
|
||||||
const query = (input?.value || "").trim().toLowerCase();
|
const query = (input?.value || "").trim().toLowerCase();
|
||||||
let visible = 0;
|
let visible = 0;
|
||||||
|
|
@ -274,12 +278,18 @@ function dataTableScript(id) {
|
||||||
root.querySelectorAll("[data-data-table-sort]").forEach((button) => {
|
root.querySelectorAll("[data-data-table-sort]").forEach((button) => {
|
||||||
button.addEventListener("click", () => {
|
button.addEventListener("click", () => {
|
||||||
const column = button.dataset.dataTableSort;
|
const column = button.dataset.dataTableSort;
|
||||||
const current = button.getAttribute("aria-sort");
|
const previousColumn = root.dataset.dataTableSortColumn || "";
|
||||||
const direction = current === "ascending" ? "descending" : "ascending";
|
const previousDirection = root.dataset.dataTableSortDirection || "";
|
||||||
|
const direction =
|
||||||
|
previousColumn === column && previousDirection === "ascending"
|
||||||
|
? "descending"
|
||||||
|
: "ascending";
|
||||||
|
|
||||||
root.querySelectorAll("[data-data-table-sort]").forEach((other) => {
|
root.querySelectorAll("[data-data-table-sort]").forEach((other) => {
|
||||||
other.removeAttribute("aria-sort");
|
other.removeAttribute("aria-sort");
|
||||||
});
|
});
|
||||||
|
root.dataset.dataTableSortColumn = column;
|
||||||
|
root.dataset.dataTableSortDirection = direction;
|
||||||
button.setAttribute("aria-sort", direction);
|
button.setAttribute("aria-sort", direction);
|
||||||
|
|
||||||
rows
|
rows
|
||||||
|
|
@ -288,7 +298,8 @@ function dataTableScript(id) {
|
||||||
const leftValue = left.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
const leftValue = left.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
||||||
const rightValue = right.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
const rightValue = right.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
||||||
const result = collator.compare(leftValue, rightValue);
|
const result = collator.compare(leftValue, rightValue);
|
||||||
return direction === "ascending" ? result : -result;
|
if (result !== 0) return direction === "ascending" ? result : -result;
|
||||||
|
return Number(left.dataset.dataTableIndex || 0) - Number(right.dataset.dataTableIndex || 0);
|
||||||
})
|
})
|
||||||
.forEach((row) => tbody.appendChild(row));
|
.forEach((row) => tbody.appendChild(row));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -256,6 +256,10 @@ function dataTableScript(id) {
|
||||||
const rows = Array.from(tbody?.querySelectorAll("tr") || []);
|
const rows = Array.from(tbody?.querySelectorAll("tr") || []);
|
||||||
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
|
||||||
|
|
||||||
|
rows.forEach((row, index) => {
|
||||||
|
row.dataset.dataTableIndex = String(index);
|
||||||
|
});
|
||||||
|
|
||||||
function applyFilter() {
|
function applyFilter() {
|
||||||
const query = (input?.value || "").trim().toLowerCase();
|
const query = (input?.value || "").trim().toLowerCase();
|
||||||
let visible = 0;
|
let visible = 0;
|
||||||
|
|
@ -274,12 +278,18 @@ function dataTableScript(id) {
|
||||||
root.querySelectorAll("[data-data-table-sort]").forEach((button) => {
|
root.querySelectorAll("[data-data-table-sort]").forEach((button) => {
|
||||||
button.addEventListener("click", () => {
|
button.addEventListener("click", () => {
|
||||||
const column = button.dataset.dataTableSort;
|
const column = button.dataset.dataTableSort;
|
||||||
const current = button.getAttribute("aria-sort");
|
const previousColumn = root.dataset.dataTableSortColumn || "";
|
||||||
const direction = current === "ascending" ? "descending" : "ascending";
|
const previousDirection = root.dataset.dataTableSortDirection || "";
|
||||||
|
const direction =
|
||||||
|
previousColumn === column && previousDirection === "ascending"
|
||||||
|
? "descending"
|
||||||
|
: "ascending";
|
||||||
|
|
||||||
root.querySelectorAll("[data-data-table-sort]").forEach((other) => {
|
root.querySelectorAll("[data-data-table-sort]").forEach((other) => {
|
||||||
other.removeAttribute("aria-sort");
|
other.removeAttribute("aria-sort");
|
||||||
});
|
});
|
||||||
|
root.dataset.dataTableSortColumn = column;
|
||||||
|
root.dataset.dataTableSortDirection = direction;
|
||||||
button.setAttribute("aria-sort", direction);
|
button.setAttribute("aria-sort", direction);
|
||||||
|
|
||||||
rows
|
rows
|
||||||
|
|
@ -288,7 +298,8 @@ function dataTableScript(id) {
|
||||||
const leftValue = left.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
const leftValue = left.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
||||||
const rightValue = right.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
const rightValue = right.querySelector(\`[data-column="\${column}"]\`)?.dataset.sortValue || "";
|
||||||
const result = collator.compare(leftValue, rightValue);
|
const result = collator.compare(leftValue, rightValue);
|
||||||
return direction === "ascending" ? result : -result;
|
if (result !== 0) return direction === "ascending" ? result : -result;
|
||||||
|
return Number(left.dataset.dataTableIndex || 0) - Number(right.dataset.dataTableIndex || 0);
|
||||||
})
|
})
|
||||||
.forEach((row) => tbody.appendChild(row));
|
.forEach((row) => tbody.appendChild(row));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue