Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion templates/assets/table-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const TableFilter = (function() {
filterState[col.id] = 'all';
});

filterState['search'] = '';

// Build the filter UI
buildFilterUI();

Expand Down Expand Up @@ -66,6 +68,14 @@ const TableFilter = (function() {
`;
});

// Search Button
html += `
<div class="filter-group">
<label for="search-input">Search:</label>
<input type="text" id="search-input" placeholder="Search by ID or description..." />
</div>`
;

// Add clear filters button and row counter
html += `
<div class="filter-group">
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down