删除搜索字段reactjs+ Antd

发布于 2025-02-10 21:55:01 字数 934 浏览 0 评论 0原文

我正在使用ReactJ和ANTD进行搜索。我要做的是,当我删除输入字段时,表将立即重新渲染并显示完整数据,而我不需要按Enter或单击搜索按钮。有什么办法吗?谢谢。

代码在此处

const [dataSource, setDataSource] = useState([])

const handleSearch = (value) => {
    let newData = [...data]
    const filterData = arrClone.filter((o) => Object.keys(o).some((k) => String(o[k])
      .toLowerCase()
      .includes(value.toLowerCase())));
    setDataSource(filterData);
  };

搜索字段和表格

<Row>
   <Col lg={24}>
       <Search
         size='large'
         placeholder='Search something'
         enterButton='Search'
         prefix={<SearchOutlined />}
         style={{ borderRadius: 5 }}
         allowClear
         onSearch={handleSearch}
       />
       <Table
         columns={columns}
         dataSource={dataSource}
         rowSelection={rowSelection}
       />
     </Col>              
</Row>

I am working on the searching of table using ReactJs and Antd. What I want to do is when I delete the input field, the table will immediately re-render and show the full data while I don't need to press Enter or click on the Search button. Is there any way to do that? Thank you.

Code here

const [dataSource, setDataSource] = useState([])

const handleSearch = (value) => {
    let newData = [...data]
    const filterData = arrClone.filter((o) => Object.keys(o).some((k) => String(o[k])
      .toLowerCase()
      .includes(value.toLowerCase())));
    setDataSource(filterData);
  };

Search field and Table

<Row>
   <Col lg={24}>
       <Search
         size='large'
         placeholder='Search something'
         enterButton='Search'
         prefix={<SearchOutlined />}
         style={{ borderRadius: 5 }}
         allowClear
         onSearch={handleSearch}
       />
       <Table
         columns={columns}
         dataSource={dataSource}
         rowSelection={rowSelection}
       />
     </Col>              
</Row>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

用心笑 2025-02-17 21:55:01

您可以将Onchange属性添加到搜索并将您的Handlesearch函数传递到其中

You can add the onChange property to Search and pass your handleSearch function into it

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文