Fixed problems pagination
This commit is contained in:
@@ -11,24 +11,52 @@ function setupProblemsPage() {
|
||||
searchInput.addEventListener('input', function() {
|
||||
clearTimeout(searchTimeout);
|
||||
searchTimeout = setTimeout(() => {
|
||||
const url = new URL(window.location);
|
||||
if (this.value.trim()) {
|
||||
url.searchParams.set('search', this.value.trim());
|
||||
if (isPaginationMode()) {
|
||||
// PAGINATION MODE - Server-side search via URL parameters
|
||||
const url = new URL(window.location);
|
||||
if (this.value.trim()) {
|
||||
url.searchParams.set('search', this.value.trim());
|
||||
} else {
|
||||
url.searchParams.delete('search');
|
||||
}
|
||||
url.searchParams.delete('page'); // Reset to first page
|
||||
window.location.href = url.toString();
|
||||
} else {
|
||||
url.searchParams.delete('search');
|
||||
// ORIGINAL MODE - Client-side instant search via Simple DataTables
|
||||
const searchValue = this.value.trim();
|
||||
const tableElement = document.querySelector('table[data-table="true"]');
|
||||
if (tableElement && window.problemsTableInstance) {
|
||||
// Enable searchable functionality
|
||||
window.problemsTableInstance.table.searchable = true;
|
||||
|
||||
// Perform the search
|
||||
if (searchValue) {
|
||||
window.problemsTableInstance.table.search(searchValue);
|
||||
} else {
|
||||
// Clear search
|
||||
window.problemsTableInstance.table.search('');
|
||||
}
|
||||
}
|
||||
}
|
||||
url.searchParams.delete('page'); // Reset to first page
|
||||
window.location.href = url.toString();
|
||||
}, 500);
|
||||
});
|
||||
|
||||
// Clear search
|
||||
clearButton.addEventListener('click', function() {
|
||||
searchInput.value = '';
|
||||
const url = new URL(window.location);
|
||||
url.searchParams.delete('search');
|
||||
url.searchParams.delete('page');
|
||||
window.location.href = url.toString();
|
||||
if (isPaginationMode()) {
|
||||
// PAGINATION MODE - Clear via URL parameters
|
||||
searchInput.value = '';
|
||||
const url = new URL(window.location);
|
||||
url.searchParams.delete('search');
|
||||
url.searchParams.delete('page');
|
||||
window.location.href = url.toString();
|
||||
} else {
|
||||
// ORIGINAL MODE - Clear via DataTables API
|
||||
searchInput.value = '';
|
||||
if (window.problemsTableInstance) {
|
||||
window.problemsTableInstance.table.search('');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -36,16 +36,19 @@ window.BrickTable = class BrickTable {
|
||||
// Special configuration for tables with custom search/sort
|
||||
const isMinifiguresTable = table.id === 'minifigures';
|
||||
const isPartsTable = table.id === 'parts';
|
||||
const isProblemsTable = table.id === 'problems';
|
||||
const isPartsTablePaginationMode = isPartsTable && table.getAttribute('data-table') === 'false';
|
||||
const hasCustomInterface = isMinifiguresTable || isPartsTablePaginationMode;
|
||||
const isProblemsTablePaginationMode = isProblemsTable && table.getAttribute('data-table') === 'false';
|
||||
const hasCustomInterface = isMinifiguresTable || isPartsTablePaginationMode || isProblemsTablePaginationMode;
|
||||
const hasCustomSearch = isPartsTable || isProblemsTable; // Parts and problems always have custom search
|
||||
|
||||
this.table = new simpleDatatables.DataTable(`#${table.id}`, {
|
||||
columns: columns,
|
||||
paging: !isPartsTablePaginationMode, // Disable built-in pagination only for parts table in pagination mode
|
||||
paging: !(isPartsTablePaginationMode || isProblemsTablePaginationMode), // Disable built-in pagination for tables in pagination mode
|
||||
pagerDelta: 1,
|
||||
perPage: per_page,
|
||||
perPageSelect: [10, 25, 50, 100, 500, 1000],
|
||||
searchable: !hasCustomInterface, // Disable built-in search for tables with custom interface
|
||||
searchable: !hasCustomSearch, // Disable built-in search for tables with custom search
|
||||
searchMethod: (table => (terms, cell, row, column, source) => table.search(terms, cell, row, column, source))(this),
|
||||
searchQuerySeparator: "",
|
||||
tableRender: () => {
|
||||
@@ -107,6 +110,8 @@ const setup_tables = (per_page) => document.querySelectorAll('table[data-table="
|
||||
window.brickTableInstance = brickTable;
|
||||
} else if (el.id === 'parts') {
|
||||
window.partsTableInstance = brickTable;
|
||||
} else if (el.id === 'problems') {
|
||||
window.problemsTableInstance = brickTable;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user