Client: Filter state is now saved in local storage

This commit is contained in:
Donkie
2023-07-06 19:18:11 +02:00
parent 887748402d
commit e42b206d7d
2 changed files with 46 additions and 0 deletions

View File

@@ -91,6 +91,9 @@ export function genericFilterer(filters: CrudFilter[]) {
console.error("Filter value must be an array of strings.");
return false;
}
if (!filter.value.length) {
continue;
}
let value = record[filter.field];
if (value === undefined || value === null) {
value = "";
@@ -148,3 +151,19 @@ export function filterPopulator(dataSource: IObj[], field: string): ColumnFilter
});
return filters;
}
/**
* Returns an array of filter values for a given field based on the provided filters.
* @param filters An array of `CrudFilter` objects that define the filtering criteria.
* @param field The field to get the filter values for.
* @returns An array of filter values for the given field.
*/
export function getFiltersForField(filters: CrudFilter[], field: string): string[] {
const filterValues: string[] = [];
filters.forEach((filter) => {
if ("field" in filter && filter.field === field) {
filterValues.push(...filter.value as string[]);
}
});
return filterValues;
}