fix searching and pagination after filtering
This commit is contained in:
@ -16,6 +16,7 @@ const ListToolbar = () => {
|
|||||||
|
|
||||||
const handleSearch = () => {
|
const handleSearch = () => {
|
||||||
table.getColumn('name')?.setFilterValue(searchValue);
|
table.getColumn('name')?.setFilterValue(searchValue);
|
||||||
|
table.setPageIndex(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -28,6 +28,7 @@ const ListToolbar = () => {
|
|||||||
|
|
||||||
const handleSearch = () => {
|
const handleSearch = () => {
|
||||||
table.getColumn('name')?.setFilterValue(searchValue);
|
table.getColumn('name')?.setFilterValue(searchValue);
|
||||||
|
table.setPageIndex(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -17,6 +17,7 @@ const ListToolbar = () => {
|
|||||||
|
|
||||||
const handleSearch = () => {
|
const handleSearch = () => {
|
||||||
table.getColumn('name')?.setFilterValue(searchPosto);
|
table.getColumn('name')?.setFilterValue(searchPosto);
|
||||||
|
table.setPageIndex(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -16,6 +16,7 @@ const ListToolbar = () => {
|
|||||||
|
|
||||||
const handleSearch = () => {
|
const handleSearch = () => {
|
||||||
table.getColumn('sucos_name')?.setFilterValue(searchValue);
|
table.getColumn('sucos_name')?.setFilterValue(searchValue);
|
||||||
|
table.setPageIndex(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -159,7 +159,7 @@ const ManageSucosContextProvider = ({ children }: { children: React.ReactNode })
|
|||||||
filter: JSON.stringify(filter)
|
filter: JSON.stringify(filter)
|
||||||
});
|
});
|
||||||
// console.log('Sucos List Response:', response?.data);
|
// 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 };
|
return { data: response?.data.list, totalCount: response?.data.total_count };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching Sucos', error);
|
console.error('Error fetching Sucos', error);
|
||||||
|
|||||||
@ -1,10 +1,23 @@
|
|||||||
import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components';
|
import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { useManageWalletContext } from '../hooks/useManageWalletContext';
|
import { useManageWalletContext } from '../hooks/useManageWalletContext';
|
||||||
|
import React, { useState } from 'react';
|
||||||
|
|
||||||
const ListToolbar = () => {
|
const ListToolbar = () => {
|
||||||
const { reload, table } = useDataGrid();
|
const { reload, table } = useDataGrid();
|
||||||
const { handleAddDialog } = useManageWalletContext();
|
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 (
|
return (
|
||||||
<div className="card-header flex-wrap gap-2 border-b-0 px-5">
|
<div className="card-header flex-wrap gap-2 border-b-0 px-5">
|
||||||
@ -16,12 +29,16 @@ const ListToolbar = () => {
|
|||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Search Wallet"
|
placeholder="Search Wallet"
|
||||||
value={(table.getColumn('wallets.name')?.getFilterValue() as string) ?? ''}
|
value={searchValue}
|
||||||
onChange={(event) =>
|
onChange={(event) => setSearchValue(event.target.value)}
|
||||||
table.getColumn('wallets.name')?.setFilterValue(event.target.value)
|
onKeyDown={handleKeyDown}
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</label>
|
</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'}>
|
{/* <DefaultTooltip title={'Filter'} placement={'top'}>
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
|||||||
@ -146,7 +146,7 @@ const ManageWalletContextProvider = ({ children }: { children: React.ReactNode }
|
|||||||
const getWalletLists = async (page: number, limit: number, sorting: any, filter: any) => {
|
const getWalletLists = async (page: number, limit: number, sorting: any, filter: any) => {
|
||||||
try {
|
try {
|
||||||
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
|
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`, {
|
const response = await GetData(`${API_URL_MASTER_DATA}/wallet/list`, {
|
||||||
limit,
|
limit,
|
||||||
page: page + 1,
|
page: page + 1,
|
||||||
|
|||||||
Reference in New Issue
Block a user