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

@ -68,7 +68,7 @@ const ManageGroups = () => {
let resGroups = groups.data.data.list.map((el: any) => { let resGroups = groups.data.data.list.map((el: any) => {
el.no = temp++; el.no = temp++;
return el; return el;
}); })
setDataGroup(resGroups); setDataGroup(resGroups);
} catch (error: any) { } catch (error: any) {
alert(error.message); alert(error.message);

View File

@ -2,10 +2,23 @@ import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import { useManagePostoAdmsContext } from '../hooks/useManagePostoAdmsContext'; import { useManagePostoAdmsContext } from '../hooks/useManagePostoAdmsContext';
import { useState } from 'react';
const ListToolbar = () => { const ListToolbar = () => {
const { table, reload } = useDataGrid(); const { table, reload } = useDataGrid();
const { handleAddDialog, handleSearchDialog } = useManagePostoAdmsContext(); 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 ( 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,11 +29,17 @@ const ListToolbar = () => {
<KeenIcon icon="magnifier" /> <KeenIcon icon="magnifier" />
<input <input
type="text" type="text"
placeholder="Search Postu Administrativo" placeholder="Search"
value={(table.getColumn('name')?.getFilterValue() as string) ?? ''} value={searchPosto}
onChange={(event) => table.getColumn('name')?.setFilterValue(event.target.value)} onChange={(event) => setSearchPosto(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"

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