Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2025
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.48 KB | Software | 0 0
  1. const ActionBar = <T,>({
  2.   globalFilter,
  3.   table,
  4.   children,
  5.   onClearFilterClick,
  6. }: ActionBarProps<T>) => {
  7.   const [searchText, setSearchText] = useState(globalFilter);
  8.   const [debouncedSearchText] = useDebouncedValue(searchText, 500);
  9.   const setGlobalFilter = table.setGlobalFilter;
  10.   const setPageIndex = table.setPageIndex;
  11.  
  12.   useEffect(() => {
  13.     setGlobalFilter(debouncedSearchText);
  14.     if (debouncedSearchText !== "") {
  15.       setPageIndex(0);
  16.     }
  17.   }, [debouncedSearchText, setGlobalFilter, setPageIndex]);
  18.  
  19.   return (
  20.     <Group justify="space-between" h="2rem">
  21.       <ActionBarButtons>{children}</ActionBarButtons>
  22.       <Group>
  23.         <Group align="center" gap="0.25rem">
  24.           <Tooltip label="Delete Filters">
  25.             <ActionIcon
  26.               onClick={() => {
  27.                 table.setSorting([]);
  28.                 table.setGlobalFilter("");
  29.                 if (onClearFilterClick !== undefined) {
  30.                   onClearFilterClick();
  31.                 }
  32.               }}
  33.               variant="subtle"
  34.               color="dark"
  35.             >
  36.               <IconFilterOff />
  37.             </ActionIcon>
  38.           </Tooltip>
  39.           <TextInput
  40.             autoFocus
  41.             leftSection={<IconSearch />}
  42.             placeholder="Suchtext"
  43.             value={searchText}
  44.             onChange={(e) => {
  45.               setSearchText(e.currentTarget.value);
  46.             }}
  47.           />
  48.         </Group>
  49.       </Group>
  50.     </Group>
  51.   );
  52. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement