Enhance row selection functionality by updating row highlight based on checkbox state and managing visibility of selection column

This commit is contained in:
Ross
2025-11-01 13:21:31 +00:00
parent ad4b06d691
commit 8e8041cdc4
+30 -1
View File
@@ -237,6 +237,11 @@ document.addEventListener('DOMContentLoaded', function() {
const checks = findRowCheckboxes();
const count = checks.filter(c => c.checked).length;
selectedCountSpan.textContent = count;
// update row highlight based on checkbox state
checks.forEach(cb => {
const tr = cb.closest('tr');
if (tr) tr.classList.toggle('table-active', cb.checked);
});
}
function setCheckboxesDisabled(disabled) {
@@ -245,8 +250,28 @@ document.addEventListener('DOMContentLoaded', function() {
});
}
// disable checkboxes by default
function hideSelectionColumn() {
if (!table) return;
// hide any th/td that contains the selection checkbox
table.querySelectorAll('th, td').forEach(function(cell) {
if (cell.querySelector && cell.querySelector('input[type="checkbox"]')) {
cell.style.display = 'none';
}
});
}
function showSelectionColumn() {
if (!table) return;
table.querySelectorAll('th, td').forEach(function(cell) {
if (cell.querySelector && cell.querySelector('input[type="checkbox"]')) {
cell.style.display = '';
}
});
}
// disable checkboxes by default and hide the selection column
setCheckboxesDisabled(true);
hideSelectionColumn();
// row click toggling
document.addEventListener('click', function(e) {
@@ -259,6 +284,8 @@ document.addEventListener('DOMContentLoaded', function() {
const cb = tr.querySelector('input[type="checkbox"]');
if (cb && !cb.disabled) {
cb.checked = !cb.checked;
// reflect highlight immediately
tr.classList.toggle('table-active', cb.checked);
updateSelectedCount();
}
});
@@ -270,10 +297,12 @@ document.addEventListener('DOMContentLoaded', function() {
toggleBtn.textContent = 'Disable row selection';
selectionControls.style.display = '';
setCheckboxesDisabled(false);
showSelectionColumn();
} else {
toggleBtn.textContent = 'Enable row selection';
selectionControls.style.display = 'none';
setCheckboxesDisabled(true);
hideSelectionColumn();
// clear any selected checkboxes
findRowCheckboxes().forEach(cb => cb.checked = false);
updateSelectedCount();