Added an export feature for the master statisticl screen

This commit is contained in:
Joao Ramos
2024-09-05 22:42:46 +01:00
parent 70de97766e
commit a61ad2cc7e
6 changed files with 309 additions and 89 deletions

29
src/utils/search.ts Normal file
View File

@@ -0,0 +1,29 @@
/*fields example = [
['id'],
['companyInformation', 'companyInformation', 'name']
]*/
const getFieldValue = (fields: string[], data: any): string => {
if (fields.length === 0) return data;
const [key, ...otherFields] = fields;
if (data[key]) return getFieldValue(otherFields, data[key]);
return data;
};
export const search = (text: string, fields: string[][], rows: any[]) => {
const searchText = text.toLowerCase();
return rows.filter((row) => {
return fields.some((fieldsKeys) => {
const value = getFieldValue(fieldsKeys, row);
if (typeof value === "string") {
return value.toLowerCase().includes(searchText);
}
if (typeof value === "number") {
return (value as Number).toString().includes(searchText);
}
});
});
}