From 585cd326b749790e51779401e584b3cb084e29a3 Mon Sep 17 00:00:00 2001 From: bagusajisaputroo Date: Wed, 16 Apr 2025 17:33:51 +0700 Subject: [PATCH] adding button on search on masterdata --- .../master/products/blocks/ListToolbar.tsx | 25 +++++++++++++++-- .../products/hooks/ManageProductsContext.tsx | 2 +- .../master/profession/blocks/ListToolbar.tsx | 27 +++++++++++++++++-- .../hooks/ManageProfessionContext.tsx | 4 +-- .../master/provider/blocks/ListToolbar.tsx | 23 ++++++++++++++-- .../provider/hooks/ManageProviderContext.tsx | 4 +-- .../master/reward/blocks/ListToolbar.tsx | 23 ++++++++++++++-- .../reward/hooks/ManageRewardContext.tsx | 5 ++-- 8 files changed, 98 insertions(+), 15 deletions(-) diff --git a/src/pages/master/products/blocks/ListToolbar.tsx b/src/pages/master/products/blocks/ListToolbar.tsx index 92bd362..efb5d3a 100644 --- a/src/pages/master/products/blocks/ListToolbar.tsx +++ b/src/pages/master/products/blocks/ListToolbar.tsx @@ -1,10 +1,24 @@ import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components'; import { useManageProductsContext } from '../hooks/useManageProductsContext'; import { Button } from '@/components/ui/button'; +import { useState } from 'react'; const ListToolbar = () => { const { table, reload } = useDataGrid(); const { handleAddDialog } = useManageProductsContext(); + const[searchProduct, setSearchProduct] = useState(''); + + + const handleSearch = ()=>{ + table.getColumn('name')?.setFilterValue(searchProduct); + table.setPageIndex(0); + } + + const handleKeyDown = (event:React.KeyboardEvent) =>{ + if(event.key==='Enter'){ + handleSearch(); + } + } return (
@@ -16,10 +30,16 @@ const ListToolbar = () => { table.getColumn('name')?.setFilterValue(event.target.value)} + value={ searchProduct} + onChange={(event) => setSearchProduct(event.target.value)} + onKeyDown={handleKeyDown} /> + + + {/* diff --git a/src/pages/master/products/hooks/ManageProductsContext.tsx b/src/pages/master/products/hooks/ManageProductsContext.tsx index 236e306..f785421 100644 --- a/src/pages/master/products/hooks/ManageProductsContext.tsx +++ b/src/pages/master/products/hooks/ManageProductsContext.tsx @@ -231,7 +231,7 @@ const ManageProductsContextProvider = ({ children }: { children: React.ReactNode ); }, meta: { - headerClassName: 'w-[100px]', + headerClassName: 'w-[100px] text-center', cellClassName: 'text-center' } } diff --git a/src/pages/master/profession/blocks/ListToolbar.tsx b/src/pages/master/profession/blocks/ListToolbar.tsx index 9c04194..0e5b23d 100644 --- a/src/pages/master/profession/blocks/ListToolbar.tsx +++ b/src/pages/master/profession/blocks/ListToolbar.tsx @@ -1,10 +1,27 @@ import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components'; import { useManageProfessionContext } from '../hooks/useManageProfessionContext'; import { Button } from '@/components/ui/button'; +import { useState } from 'react'; +import { set } from 'date-fns'; const ListToolbar = () => { const { reload, table } = useDataGrid(); const { handleAddDialog } = useManageProfessionContext(); + const [searchProfession, setSearchProfession]= useState(''); + + const handleKeyDown = (event: React.KeyboardEvent) =>{ + if(event.key==='Enter'){ + handleSearch(); + } + } + + const handleSearch = () =>{ + table.getColumn('name')?.setFilterValue(searchProfession); + table.setPageIndex(0); + } + + + return (
@@ -16,12 +33,18 @@ const ListToolbar = () => { - table.getColumn('name')?.setFilterValue(event.target.value) + setSearchProfession(event.target.value) } + onKeyDown={handleKeyDown} /> + + + {/* + {/* +