From aab727dbb04893c50d5c837f0aca3d1a207e8d43 Mon Sep 17 00:00:00 2001 From: AminGhasempoor Date: Mon, 15 Apr 2024 10:37:03 +0330 Subject: [PATCH] add filter summary text --- src/components/FilterColumn.jsx | 2 +- src/lib/contexts/tableSetting.jsx | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/components/FilterColumn.jsx b/src/components/FilterColumn.jsx index 46e156b..3c86f51 100644 --- a/src/components/FilterColumn.jsx +++ b/src/components/FilterColumn.jsx @@ -56,7 +56,7 @@ function FilterColumn({ columns }) { const initialValues = columns.reduce((acc, column) => { if (column.enableColumnFilter) { - const filter = settingStore?.[userId]?.[pageName]?.[tableName]?.['filters'].find((filter) => filter.id === column.id); + const filter = settingStore?.[userId]?.[pageName]?.[tableName]?.['filters']?.find((filter) => filter.id === column.id); if (column.filterFn === 'betweenNum' || column.filterFn === 'betweenDate') { acc[column.id] = filter?.value || ["", ""]; } diff --git a/src/lib/contexts/tableSetting.jsx b/src/lib/contexts/tableSetting.jsx index d787d87..f619afa 100644 --- a/src/lib/contexts/tableSetting.jsx +++ b/src/lib/contexts/tableSetting.jsx @@ -57,7 +57,7 @@ export const TableSettingProvider = ({children}) => { const SummaryTextMessage = (values, columns) => { let SummaryText = ""; let HideText = ""; - let FilterText; + let FilterText = ""; let SortText = ""; if (values.sorts && values.sorts.length > 0) { @@ -67,7 +67,17 @@ export const TableSettingProvider = ({children}) => { _list.push(`${_column.header}` + `(${sort.desc ? "نزولی" : "صعودی"})`) } if (_list.length > 0) - SortText = " مرتب شده بر اساس " + _list.join(", ") + SortText = " مرتب شده بر اساس : " + _list.join(", ") + } + if (values.filters && values.filters.length > 0){ + const _list = [] + for (const filter of values.filters){ + const _column = columns.find(column => column.id == filter.id) + _list.push(`${_column.header}`) + } + console.log(_list) + if (_list.length > 0) + FilterText = " فیلتر شده بر اساس : " + _list.join(", ") } if (values.hides) { @@ -84,15 +94,24 @@ export const TableSettingProvider = ({children}) => { } } - if (HideText || SortText) { + if (HideText || SortText || FilterText) { if (SortText) { SummaryText += SortText; if (HideText) { SummaryText += " ; "; } + if (FilterText){ + SummaryText += " ; "; + } } if (HideText) { SummaryText += HideText; + if (FilterText) { + SummaryText += " ; "; + } + } + if (FilterText){ + SummaryText += FilterText } }