feat: add per-column filtering and sticky header support to DeesTable component
This commit is contained in:
@@ -41,19 +41,39 @@ export function getViewData<T>(
|
||||
effectiveColumns: Column<T>[],
|
||||
sortKey?: string,
|
||||
sortDir?: 'asc' | 'desc' | null,
|
||||
filterText?: string
|
||||
filterText?: string,
|
||||
columnFilters?: Record<string, string>
|
||||
): T[] {
|
||||
let arr = data.slice();
|
||||
const ft = (filterText || '').trim().toLowerCase();
|
||||
if (ft) {
|
||||
const cf = columnFilters || {};
|
||||
const cfKeys = Object.keys(cf).filter((k) => (cf[k] ?? '').trim().length > 0);
|
||||
if (ft || cfKeys.length > 0) {
|
||||
arr = arr.filter((row) => {
|
||||
for (const col of effectiveColumns) {
|
||||
if (col.hidden) continue;
|
||||
// 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();
|
||||
if (s.includes(ft)) return true;
|
||||
const needle = String(cf[k]).toLowerCase();
|
||||
if (!s.includes(needle)) return false;
|
||||
}
|
||||
return false;
|
||||
// global filter (OR across visible columns)
|
||||
if (ft) {
|
||||
let any = false;
|
||||
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;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
if (!sortKey || !sortDir) return arr;
|
||||
@@ -75,4 +95,3 @@ export function getViewData<T>(
|
||||
});
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user