fix searching and pagination after filtering

This commit is contained in:
Wikzyy
2025-04-16 14:07:14 +07:00
parent 1ddda4d478
commit ed4b2f1471
7 changed files with 27 additions and 6 deletions

View File

@ -16,6 +16,7 @@ const ListToolbar = () => {
const handleSearch = () => {
table.getColumn('name')?.setFilterValue(searchValue);
table.setPageIndex(0);
};
return (

View File

@ -28,6 +28,7 @@ const ListToolbar = () => {
const handleSearch = () => {
table.getColumn('name')?.setFilterValue(searchValue);
table.setPageIndex(0);
};
return (

View File

@ -17,6 +17,7 @@ const ListToolbar = () => {
const handleSearch = () => {
table.getColumn('name')?.setFilterValue(searchPosto);
table.setPageIndex(0);
};
return (

View File

@ -16,6 +16,7 @@ const ListToolbar = () => {
const handleSearch = () => {
table.getColumn('sucos_name')?.setFilterValue(searchValue);
table.setPageIndex(0);
};
return (

View File

@ -159,7 +159,7 @@ const ManageSucosContextProvider = ({ children }: { children: React.ReactNode })
filter: JSON.stringify(filter)
});
// console.log('Sucos List Response:', response?.data);
setSucos(response?.data.list || []); // Pastikan default value adalah array kosong
setSucos(response?.data.list || []);
return { data: response?.data.list, totalCount: response?.data.total_count };
} catch (error) {
console.error('Error fetching Sucos', error);

View File

@ -1,10 +1,23 @@
import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components';
import { Button } from '@/components/ui/button';
import { useManageWalletContext } from '../hooks/useManageWalletContext';
import React, { useState } from 'react';
const ListToolbar = () => {
const { reload, table } = useDataGrid();
const { handleAddDialog } = useManageWalletContext();
const [searchValue, setSearchValue] = useState('');
const handleKeyDown = (event: React.KeyboardEvent) => {
if (event.key === 'Enter') {
handleSearch();
}
};
const handleSearch = () => {
table.getColumn('wallets.name')?.setFilterValue(searchValue);
table.setPageIndex(0);
};
return (
<div className="card-header flex-wrap gap-2 border-b-0 px-5">
@ -16,12 +29,16 @@ const ListToolbar = () => {
<input
type="text"
placeholder="Search Wallet"
value={(table.getColumn('wallets.name')?.getFilterValue() as string) ?? ''}
onChange={(event) =>
table.getColumn('wallets.name')?.setFilterValue(event.target.value)
}
value={searchValue}
onChange={(event) => setSearchValue(event.target.value)}
onKeyDown={handleKeyDown}
/>
</label>
<DefaultTooltip title={'Search'} placement={'top'}>
<Button variant="outline" className="h-7.5" onClick={handleSearch}>
<KeenIcon icon="magnifier" />
</Button>
</DefaultTooltip>
{/* <DefaultTooltip title={'Filter'} placement={'top'}>
<Button
variant="outline"

View File

@ -146,7 +146,7 @@ const ManageWalletContextProvider = ({ children }: { children: React.ReactNode }
const getWalletLists = async (page: number, limit: number, sorting: any, filter: any) => {
try {
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
filter = filter.length == 0 ? {} : { name: { like: `%${filter[0].value?.toLowerCase()}%` } };
filter = filter.length == 0 ? {} : { 'wallets.name': { like: `%${filter[0].value?.toLowerCase()}%` } };
const response = await GetData(`${API_URL_MASTER_DATA}/wallet/list`, {
limit,
page: page + 1,