update for filter transaction
This commit is contained in:
@ -16,18 +16,17 @@ const ListToolbar = () => {
|
|||||||
|
|
||||||
// Set the initial state for trxDate
|
// Set the initial state for trxDate
|
||||||
const [trxDate, settrxDate] = useState({ from: '', to: '' });
|
const [trxDate, settrxDate] = useState({ from: '', to: '' });
|
||||||
|
|
||||||
const [statusApproval, setStatusApproval] = useState<string>(
|
const [statusApproval, setStatusApproval] = useState<string>(
|
||||||
(table.getColumn('status_approve')?.getFilterValue() as string) ?? ''
|
(table.getColumn('status_approve')?.getFilterValue() as string) ?? ''
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
table.getColumn('status_approve')?.setFilterValue(statusApproval);
|
table.getColumn('status_approve')?.setFilterValue(statusApproval);
|
||||||
table.setPageIndex(0);
|
table.setPageIndex(0);
|
||||||
}, 200);
|
}, 200);
|
||||||
return () => clearTimeout(timer);
|
return () => clearTimeout(timer);
|
||||||
}, [statusApproval, table]);
|
}, [statusApproval, table]);
|
||||||
|
|
||||||
// Function to format date to YYYY-MM-DD
|
// Function to format date to YYYY-MM-DD
|
||||||
const formatDate = (date: Date): string => {
|
const formatDate = (date: Date): string => {
|
||||||
@ -139,7 +138,9 @@ const ListToolbar = () => {
|
|||||||
const today = new Date();
|
const today = new Date();
|
||||||
const firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
|
const firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
|
||||||
|
|
||||||
|
// Resetting all filters
|
||||||
setSearchValue('');
|
setSearchValue('');
|
||||||
|
setStatusApproval('');
|
||||||
settrxDate({
|
settrxDate({
|
||||||
from: formatDate(firstDayOfMonth),
|
from: formatDate(firstDayOfMonth),
|
||||||
to: formatDate(today),
|
to: formatDate(today),
|
||||||
@ -149,7 +150,7 @@ const ListToolbar = () => {
|
|||||||
table.getColumn('status_approve')?.setFilterValue('');
|
table.getColumn('status_approve')?.setFilterValue('');
|
||||||
table.setPageIndex(0);
|
table.setPageIndex(0);
|
||||||
|
|
||||||
reload();
|
reload(); // Reload table data
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<KeenIcon icon="arrows-circle" />
|
<KeenIcon icon="arrows-circle" />
|
||||||
@ -159,7 +160,6 @@ const ListToolbar = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default ListToolbar;
|
export default ListToolbar;
|
||||||
|
|||||||
@ -164,9 +164,11 @@ const ListToolbar = () => {
|
|||||||
variant="outline"
|
variant="outline"
|
||||||
className="h-7.5"
|
className="h-7.5"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
// Preserve trxDate values (from, to) and reset others
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
const firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
|
const firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
|
||||||
|
|
||||||
|
// Only reset filters excluding from and to
|
||||||
setSearchValue('');
|
setSearchValue('');
|
||||||
setStatusValue('');
|
setStatusValue('');
|
||||||
setTypeValue('');
|
setTypeValue('');
|
||||||
@ -175,6 +177,7 @@ const ListToolbar = () => {
|
|||||||
to: formatDate(today),
|
to: formatDate(today),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Reset other filters except for date range
|
||||||
table.setColumnFilters([
|
table.setColumnFilters([
|
||||||
{ id: 'code', value: '' },
|
{ id: 'code', value: '' },
|
||||||
{ id: 'status', value: '' },
|
{ id: 'status', value: '' },
|
||||||
|
|||||||
Reference in New Issue
Block a user