From cd64bf3e7cce455e0c3ffce3e2d5850630adde44 Mon Sep 17 00:00:00 2001 From: Arpit Date: Mon, 27 Sep 2021 09:08:34 +0530 Subject: [PATCH] Fixes table-search (#836) * fixed table-search and able to search immediately as you type * remove console.log --- .../Editor/Components/Table/GlobalFilter.jsx | 53 ++++++++++++++++ .../src/Editor/Components/Table/Table.jsx | 61 ++++--------------- 2 files changed, 66 insertions(+), 48 deletions(-) create mode 100644 frontend/src/Editor/Components/Table/GlobalFilter.jsx diff --git a/frontend/src/Editor/Components/Table/GlobalFilter.jsx b/frontend/src/Editor/Components/Table/GlobalFilter.jsx new file mode 100644 index 0000000000..015779b110 --- /dev/null +++ b/frontend/src/Editor/Components/Table/GlobalFilter.jsx @@ -0,0 +1,53 @@ +import React from 'react'; +// Table Search +export const GlobalFilter = ({ + preGlobalFilteredRows, + globalFilter, + useAsyncDebounce, + setGlobalFilter, + onComponentOptionChanged, + component, + serverSideSearch, + onEvent, +}) => { + const count = preGlobalFilteredRows.length; + const [value, setValue] = React.useState(globalFilter); + const onChange = useAsyncDebounce((filterValue) => { + setGlobalFilter(filterValue || undefined); + }, 200); + + const handleSearchTextChange = (text) => { + setValue(text); + onChange(text); + + onComponentOptionChanged(component, 'searchText', text).then(() => { + if (serverSideSearch === true) { + onEvent('onSearch', { component, data: {} }); + } + }); + }; + + return ( +
+ Search:{' '} + { + handleSearchTextChange(e.target.value); + }} + onKeyDown={(e) => { + if (e.key === 'Enter') { + handleSearchTextChange(e.target.value); + } + }} + onChange={(e) => onChange(e.target.value)} + placeholder={`${count} records`} + style={{ + border: '0', + }} + /> +
+ ); +}; diff --git a/frontend/src/Editor/Components/Table/Table.jsx b/frontend/src/Editor/Components/Table/Table.jsx index 7380683c4b..e95dad3004 100644 --- a/frontend/src/Editor/Components/Table/Table.jsx +++ b/frontend/src/Editor/Components/Table/Table.jsx @@ -21,9 +21,8 @@ import { Tags } from './Tags'; import { Radio } from './Radio'; import { Toggle } from './Toggle'; import { Datepicker } from './Datepicker'; - +import { GlobalFilter } from './GlobalFilter'; var _ = require('lodash'); - export function Table({ id, width, @@ -671,47 +670,6 @@ export function Table({ } }, [state.columnResizing.isResizingColumn]); - function GlobalFilter() { - const count = preGlobalFilteredRows.length; - const [value, setValue] = React.useState(state.globalFilter); - const onChange = useAsyncDebounce((filterValue) => { - setGlobalFilter(filterValue || undefined); - }, 200); - - const handleSearchTextChange = (text) => { - setValue(text); - onChange(text); - - onComponentOptionChanged(component, 'searchText', text).then(() => { - if (serverSideSearch === true) { - onEvent('onSearch', { component, data: {} }); - } - }); - }; - - return ( -
- Search:{' '} - { - handleSearchTextChange(e.target.value); - }} - onKeyDown={(e) => { - if (e.key === 'Enter') { - handleSearchTextChange(e.target.value); - } - }} - placeholder={`${count} records`} - style={{ - border: '0', - }} - /> -
- ); - } - return (
- {displaySearchBox && ( -
- -
- )} +
+ +
)}