Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

262
Views
Antd Table Search and Reset functions not functioning

I am trying to implement search and reset functions in Antd table. The reset(clearAll) function is not returning the table back to its initial state when clicked. The search code blocks logs these errors on the console === >

     TS2322: Type 'any[]' is not assignable to type 'undefined'.
     280 |   };
     281 |   const globalSearch = () => {
   > 282 |     filteredValue = modifiedData.filter(value => {
    |     ^^^^^^^^^^^^^
     283 |       return (
     284 |         value.name.toLowerCase().includes(searchText.toLowerCase()) ||
  

And

    TS2339: Property 'length' does not exist on type 'never'.
     319 |             }}
     320 |             columns={mergedColumns}
   > 321 |             dataSource={filteredValue && filteredValue.length ? filteredValue : 
     modifiedData}
    |                                                        ^^^^^^

These are the codes

     const [sortedInfo, setSortedInfo] = useState({});  
     const [searchText, setSearchText] = useState('');
     let [filteredValue] = useState();

Code block for resetting the table

const clearAll = () => {
setSortedInfo({});       ===> coming from the sorted Values
setSearchText('');
loadData();           ====> Data from the API loads when useEffect is called
};

Code block for Search

      const handleSearch = e => {
      setSearchText(e.target.value);
      if (e.target.value === '') {
       loadData();
      }
     };
     const globalSearch = () => {
     filteredValue = modifiedData.filter(value => {
      return (
      value.name.toLowerCase().includes(searchText.toLowerCase()) ||
      value.tankThreatLevelColor.toLowerCase().includes(searchText.toLowerCase())
     );
      });
     setGridData(filteredValue);
    };

In the jsx

      <Space style={{ marginBottom: 16 }}>
      <Input placeholder="Enter Search Text" onChange={handleSearch} type="text" allowClear 
       value={searchText} />
      <Button type="primary" onClick={globalSearch}>
        Search
      </Button>
      <Button onClick={clearAll}>Reset Table</Button>
      </Space>

        <Table
        components={{
          body: {
            cell: EditableCell,
          },
        }}
        columns={mergedColumns}
        dataSource={filteredValue && filteredValue.length ? filteredValue : modifiedData}
        bordered
        
      />

Much Gratitude in anticipation ๐Ÿ™๐Ÿพ

about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

Update your globalSearch() with following code.

replace

value.tankThreatLevelColor.toLowerCase().includes(searchText.toLowerCase())

with

value.username.toLowerCase().includes(searchText.toLowerCase())

as there is no column with name tankThreatLevelColor

Error screenshot

Update your globalSearch() with following code.

const globalSearch = () => {
    filteredValue = modifiedData.filter((value) => {
    return (
      value.name.toLowerCase().includes(searchText.toLowerCase()) ||
      value.username.toLowerCase().includes(searchText.toLowerCase())
    );
  });
    setGridData(filteredValue);
 };

Search by name result:

Screenshot

Search by username result:

Screenshot

After reset: Screenshot

about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!