update method search

This commit is contained in:
wayanrivan
2025-05-06 17:45:25 +07:00
parent 4d0d6fd039
commit f0ed1cebe6
4 changed files with 162 additions and 61 deletions

View File

@ -15,9 +15,7 @@ const ListToolbar = () => {
const { table, reload } = useDataGrid();
const [trxDate, settrxDate] = useState({ from: '', to: '' });
const [searchValue, setSearchValue] = useState<string>(
(table.getColumn('code')?.getFilterValue() as string) ?? ''
);
const [searchValue, setSearchValue] = useState<string>();
// const [statusValue, setStatusValue] = useState<string>(
// (table.getColumn('status')?.getFilterValue() as string) ?? ''
@ -27,18 +25,12 @@ const ListToolbar = () => {
(table.getState().columnFilters.find(f => f.id === 'kind')?.value as string) ?? ''
);
const [typeSearchValue, setSearchTypeValue] = useState<string>();
const formatDate = (date: Date): string => {
return date.toISOString().split('T')[0];
};
useEffect(() => {
const timer = setTimeout(() => {
table.getColumn('code')?.setFilterValue(searchValue);
table.setPageIndex(0);
}, 200);
return () => clearTimeout(timer);
}, [searchValue, table]);
// useEffect(() => {
// const timer = setTimeout(() => {
@ -59,6 +51,30 @@ const ListToolbar = () => {
return () => clearTimeout(timer);
}, [typeValue, table]);
useEffect(() => {
const timer = setTimeout(() => {
// Add search type filter to column filters
table.setColumnFilters((prev) => [
...prev.filter((f) => f.id !== 'searchtype'),
{ id: 'searchtype', value: typeSearchValue },
]);
table.setPageIndex(0);
}, 200);
return () => clearTimeout(timer);
}, [typeSearchValue, table]);
useEffect(() => {
const timer = setTimeout(() => {
table.getColumn('code')?.setFilterValue(searchValue);
table.setPageIndex(0);
}, 200);
return () => clearTimeout(timer);
}, [searchValue, table]);
useEffect(() => {
const today = new Date();
// const firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
@ -135,8 +151,8 @@ const ListToolbar = () => {
setTypeValue(value);
}}
>
<SelectTrigger className="input input-sm w-[160px] h-[31px]">
<SelectValue placeholder="Select Type" />
<SelectTrigger className="input input-sm w-[250px] h-[31px]">
<SelectValue placeholder="Select Transaction Type" />
</SelectTrigger>
<SelectContent>
<SelectItem value="T">TRANSFER</SelectItem>
@ -148,11 +164,27 @@ const ListToolbar = () => {
</SelectContent>
</Select>
<Select
value={typeSearchValue}
onValueChange={(value) => {
setSearchTypeValue(value);
}}
>
<SelectTrigger className="input input-sm w-[250px] h-[31px]">
<SelectValue placeholder="Select Search Type" />
</SelectTrigger>
<SelectContent>
<SelectItem value="msisdn">MSISDN</SelectItem>
<SelectItem value="fullname">FULLNAME</SelectItem>
<SelectItem value="trxid">TRANSACTION ID</SelectItem>
</SelectContent>
</Select>
<label className="input input-sm w-1/3">
<KeenIcon icon="magnifier" />
<input
type="text"
placeholder="Search Transaction ID, MSISDN, Or Full Name Customer"
placeholder={`Search ${typeSearchValue || ''}`} // Use typeSearchValue if it's set, else fallback to an empty string
value={searchValue}
onChange={(event) => setSearchValue(event.target.value)}
/>
@ -171,6 +203,7 @@ const ListToolbar = () => {
// Only reset filters excluding from and to
setSearchValue('');
setSearchTypeValue('');
// setStatusValue('');
setTypeValue('');
settrxDate({