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 // 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;

View File

@ -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: '' },