feat: enhance DeesTable with server-side search and Lucene filtering capabilities

This commit is contained in:
2025-09-16 15:46:44 +00:00
parent 286a6f9088
commit f739bb608e
5 changed files with 341 additions and 34 deletions

View File

@@ -42,7 +42,9 @@ export function getViewData<T>(
sortKey?: string,
sortDir?: 'asc' | 'desc' | null,
filterText?: string,
columnFilters?: Record<string, string>
columnFilters?: Record<string, string>,
filterMode: 'table' | 'data' = 'table',
lucenePredicate?: (row: T) => boolean
): T[] {
let arr = data.slice();
const ft = (filterText || '').trim().toLowerCase();
@@ -52,23 +54,39 @@ export function getViewData<T>(
arr = arr.filter((row) => {
// column filters (AND across columns)
for (const k of cfKeys) {
const col = effectiveColumns.find((c) => String(c.key) === k);
if (!col || col.hidden || col.filterable === false) continue;
const val = getCellValue(row, col);
const s = String(val ?? '').toLowerCase();
const needle = String(cf[k]).toLowerCase();
if (!s.includes(needle)) return false;
}
// global filter (OR across visible columns)
if (ft) {
let any = false;
for (const col of effectiveColumns) {
if (col.hidden) continue;
if (filterMode === 'data') {
// raw object check for that key
const val = (row as any)[k];
const s = String(val ?? '').toLowerCase();
const needle = String(cf[k]).toLowerCase();
if (!s.includes(needle)) return false;
} else {
const col = effectiveColumns.find((c) => String(c.key) === k);
if (!col || col.hidden || col.filterable === false) continue;
const val = getCellValue(row, col);
const s = String(val ?? '').toLowerCase();
if (s.includes(ft)) {
any = true;
break;
const needle = String(cf[k]).toLowerCase();
if (!s.includes(needle)) return false;
}
}
// global filter (OR across visible columns) or lucene predicate
if (ft) {
if (lucenePredicate) {
if (!lucenePredicate(row)) return false;
return true;
}
let any = false;
if (filterMode === 'data') {
for (const val of Object.values(row as any)) {
const s = String(val ?? '').toLowerCase();
if (s.includes(ft)) { any = true; break; }
}
} else {
for (const col of effectiveColumns) {
if (col.hidden) continue;
const val = getCellValue(row, col);
const s = String(val ?? '').toLowerCase();
if (s.includes(ft)) { any = true; break; }
}
}
if (!any) return false;