diff --git a/templates/assets/table-filter.js b/templates/assets/table-filter.js index 5d243f7..b20d74c 100644 --- a/templates/assets/table-filter.js +++ b/templates/assets/table-filter.js @@ -29,6 +29,8 @@ const TableFilter = (function() { filterState[col.id] = 'all'; }); + filterState['search'] = ''; + // Build the filter UI buildFilterUI(); @@ -66,6 +68,14 @@ const TableFilter = (function() { `; }); + // Search Button + html += ` +
+ + +
` + ; + // Add clear filters button and row counter html += `
@@ -136,6 +146,15 @@ const TableFilter = (function() { } }); + // Attach change listeners for the search box + const searchInput = document.getElementById('search-input'); + if (searchInput) { + searchInput.addEventListener('input', (e) => { + filterState['search'] = e.target.value.toLowerCase().trim(); + applyFilters(); + }); + } + // Attach click listener to clear button const clearBtn = document.getElementById('clear-filters'); if (clearBtn) { @@ -163,7 +182,13 @@ const TableFilter = (function() { return rowValue === filterValue; }); - if (matches) { + // Check if description or Id matchesthe searchTerm + const searchTerm = filterState['search']; + const searchableTerm = row.cells[0].textContent.toLowerCase() + row.cells[1].textContent.toLowerCase(); + const matchesSearch = !searchTerm || searchableTerm.includes(searchTerm); + + + if (matches && matchesSearch) { row.classList.remove('filtered-out'); visibleCount++; } else { @@ -187,6 +212,11 @@ const TableFilter = (function() { filterState[col.id] = 'all'; }); + // Reset search box to empty + const searchInput = document.getElementById('search-input'); + if (searchInput) searchInput.value = ''; + filterState['search'] = ''; + // Remove all filtered-out classes const table = document.querySelector(config.tableSelector); if (table) {