update filter search municipio

This commit is contained in:
Wikzyy
2025-04-15 22:22:26 +07:00
parent 3552aa4abf
commit 09d6bb87a5
3 changed files with 38 additions and 8 deletions

View File

@ -2,10 +2,23 @@ import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components';
import { Button } from '@/components/ui/button';
import { useManagePostoAdmsContext } from '../hooks/useManagePostoAdmsContext';
import { useState } from 'react';
const ListToolbar = () => {
const { table, reload } = useDataGrid();
const { handleAddDialog, handleSearchDialog } = useManagePostoAdmsContext();
const [searchPosto, setSearchPosto] = useState('');
const [searchMunicipio, setSearchMunicipio] = useState('');
const handleKeyDown = (event: React.KeyboardEvent) => {
if (event.key === 'Enter') {
handleSearch();
}
};
const handleSearch = () => {
table.getColumn('name')?.setFilterValue(searchPosto);
};
return (
<div className="card-header flex-wrap gap-2 border-b-0 px-5">
@ -16,11 +29,17 @@ const ListToolbar = () => {
<KeenIcon icon="magnifier" />
<input
type="text"
placeholder="Search Postu Administrativo"
value={(table.getColumn('name')?.getFilterValue() as string) ?? ''}
onChange={(event) => table.getColumn('name')?.setFilterValue(event.target.value)}
placeholder="Search"
value={searchPosto}
onChange={(event) => setSearchPosto(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

@ -97,7 +97,7 @@ const ManagePostoAdmsContextProvider = ({ children }: { children: React.ReactNod
}
},
{
accessorFn: (row) => row.municipios_name,
accessorFn: (row) => row.Municipios_name,
id: 'municipios_name',
header: ({ column }) => <DataGridColumnHeader title="Municipio Name" column={column} />,
enableSorting: false,
@ -139,17 +139,28 @@ const ManagePostoAdmsContextProvider = ({ children }: { children: React.ReactNod
[handleEditDialog, handleDeleteDialog]
);
const getPostoAdmsLists = async (page: number, limit: number, sorting: any, filter: any) => {
const getPostoAdmsLists = async (
page: number,
limit: number,
sorting: any,
filters: any[] = []
) => {
try {
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
filter = filter.length == 0 ? {} : { any: filter[0].value?.toLowerCase() };
// filter = filter.length == 0 ? {} : { any: filter[0].value?.toLowerCase() };
let filter = '';
if (filters.length > 0 && filters[0].value) {
filter = filters[0].value.toLowerCase();
}
const response = await GetData(`${API_URL}/postoadms/list`, {
limit,
page: page + 1,
with_deleted: false,
order_field: sorting[0].id,
order_direction: sorting[0].desc ? 'DESC' : 'ASC',
filter: JSON.stringify(filter)
filter
});
// console.log(response?.data);
// const sortedList = response.data.data.list.sort((a: PostoAdmsProps, b: PostoAdmsProps) => {