update for filter transaction

This commit is contained in:
wayanrivan
2025-04-21 15:44:11 +07:00
parent 2db0287cc2
commit 6a81242a68
2 changed files with 12 additions and 9 deletions

View File

@ -16,18 +16,17 @@ const ListToolbar = () => {
// Set the initial state for trxDate
const [trxDate, settrxDate] = useState({ from: '', to: '' });
const [statusApproval, setStatusApproval] = useState<string>(
(table.getColumn('status_approve')?.getFilterValue() as string) ?? ''
);
useEffect(() => {
const timer = setTimeout(() => {
table.getColumn('status_approve')?.setFilterValue(statusApproval);
table.setPageIndex(0);
}, 200);
return () => clearTimeout(timer);
}, [statusApproval, table]);
const timer = setTimeout(() => {
table.getColumn('status_approve')?.setFilterValue(statusApproval);
table.setPageIndex(0);
}, 200);
return () => clearTimeout(timer);
}, [statusApproval, table]);
// Function to format date to YYYY-MM-DD
const formatDate = (date: Date): string => {
@ -139,7 +138,9 @@ const ListToolbar = () => {
const today = new Date();
const firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
// Resetting all filters
setSearchValue('');
setStatusApproval('');
settrxDate({
from: formatDate(firstDayOfMonth),
to: formatDate(today),
@ -149,7 +150,7 @@ const ListToolbar = () => {
table.getColumn('status_approve')?.setFilterValue('');
table.setPageIndex(0);
reload();
reload(); // Reload table data
}}
>
<KeenIcon icon="arrows-circle" />
@ -159,7 +160,6 @@ const ListToolbar = () => {
</div>
</div>
);
};
export default ListToolbar;

View File

@ -164,9 +164,11 @@ const ListToolbar = () => {
variant="outline"
className="h-7.5"
onClick={() => {
// Preserve trxDate values (from, to) and reset others
const today = new Date();
const firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
// Only reset filters excluding from and to
setSearchValue('');
setStatusValue('');
setTypeValue('');
@ -175,6 +177,7 @@ const ListToolbar = () => {
to: formatDate(today),
});
// Reset other filters except for date range
table.setColumnFilters([
{ id: 'code', value: '' },
{ id: 'status', value: '' },