简体   繁体   English

如何使用Ant Design Auto Complete(React JS)搜索和查找表详细信息

[英]How to search and find table details using ant design auto complete(react js)

I am using ant design auto complete, vx is my Datasource array(all name list only) and empData is my table datasource .Here my problem is how to search and find the correct details from person name and how to write onSearch function when i select the name and press the search button? 我正在使用ant design自动完成,vx是我的数据源数组(仅全名列表),empData是我的表数据源。这是我的问题是如何从人名中搜索和查找正确的详细信息以及当我选择时如何编写onSearch函数名称,然后按搜索按钮?

<AutoComplete
    dataSource={vx}
    placeholder="type"
    onChange={this.handleChange
    onPressEnter={this.onSearch}
   filterOption={(inpvalueutValue, option) => option.props.children.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1} />

 <Button type="primary" onClick={this.onSearch}>Search</Button>

This is my handleChange function 这是我的handleChange函数

handleChange(value) {
    console.log(`selected  ${value}`);

  }

This is my table 这是我的桌子

 <Table pagination={{ pageSize: 10 }} columns={columns}  dataSource={this.state.empData} />

Make this changes to your autocomplete and button tags, The dropdown was auto closing after option select. 对您的自动完成和按钮标签进行此更改,选择选项后,下拉列表会自动关闭。 Try to handle the way you are doing it now. 尝试处理当前的操作方式。 However, search is working fine. 但是,搜索工作正常。

handleSearch = (selectedKeys, confirm) => () => {
        confirm();
        this.setState({ searchText: selectedKeys[0] });
      }

const dataSource1 = ['Amal', 'Chamika', 'Unknown'];

const columns = [{
          title: 'Name',
          dataIndex: 'name',
          key: 'name',
          filterDropdown: ({ setSelectedKeys, selectedKeys, confirm}) => (
            <div>
              <AutoComplete
                dataSource={dataSource1}
                placeholder="Search name"
                value={selectedKeys[0]}
                onChange={value => setSelectedKeys(value ? [value] : [])}
              />
            <Button type="primary" onClick={this.handleSearch(selectedKeys, confirm)}>Search</Button>
            </div>
          ),
          filterIcon: filtered => <Icon type="smile-o" style={{ color: filtered ? '#108ee9' : '#aaa' }} />,
          onFilter: (value, record) => record.name.toLowerCase().includes(value.toLowerCase()),
          render: (text) => text,
        }, {
          title: 'Age',
          dataIndex: 'age',
          key: 'age',
        }, {
          title: 'Address',
          dataIndex: 'address',
          key: 'address',
        }];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM