Фильтр и таблица с датой выбора в реакции - PullRequest
0 голосов
/ 15 апреля 2020

Ниже приведен код для таблицы проектирования Ant с фильтрацией объекта с использованием поля ввода, но я хочу, чтобы он преобразовал его для поля даты ввода даты вместо поля ввода, но не понял, как его преобразовать.

const data = [
  {
    key: '1',
    date: '2020-04-01',
  },
  {
    key: '2',
    date: '2020-04-04',
  },
  {
    key: '3',
    date: '2020-04-03',
  },
  {
    key: '4',
   date: '2020-04-02',
  },
];

class App extends React.Component {
  state = {
    searchText: '',
    searchedColumn: '',
  };

  getColumnSearchProps = dataIndex => ({
    filterDropdown: ({ setSelectedKeys, selectedKeys, confirm, clearFilters }) => (
      <div style={{ padding: 8 }}>
        <Input
          ref={node => {
            this.searchInput = node;
          }}
          placeholder={`Search ${dataIndex}`}
          value={selectedKeys[0]}
          onChange={e => setSelectedKeys(e.target.value ? [e.target.value] : [])}
          onPressEnter={() => this.handleSearch(selectedKeys, confirm, dataIndex)}
          style={{ width: 188, marginBottom: 8, display: 'block' }}
        />
        <Button
          type="primary"
          onClick={() => this.handleSearch(selectedKeys, confirm, dataIndex)}
          icon={<SearchOutlined />}
          size="small"
          style={{ width: 90, marginRight: 8 }}
        >
          Search
        </Button>
        <Button onClick={() => this.handleReset(clearFilters)} size="small" style={{ width: 90 }}>
          Reset
        </Button>
      </div>
    ),
    filterIcon: filtered => <SearchOutlined style={{ color: filtered ? '#1890ff' : undefined }} />,
    onFilter: (value, record) =>
      record[dataIndex]
        .toString()
        .toLowerCase()
        .includes(value.toLowerCase()),
    onFilterDropdownVisibleChange: visible => {
      if (visible) {
        setTimeout(() => this.searchInput.select());
      }
    },
    render: text =>
      this.state.searchedColumn === dataIndex ? (
        <Highlighter
          highlightStyle={{ backgroundColor: '#ffc069', padding: 0 }}
          searchWords={[this.state.searchText]}
          autoEscape
          textToHighlight={text.toString()}
        />
      ) : (
        text
      ),
  });

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

  handleReset = clearFilters => {
    clearFilters();
    this.setState({ searchText: '' });
  };

  render() {
    const columns = [
      {
        title: 'Date',
        dataIndex: 'name',
        key: 'name',
        width: '30%',
        ...this.getColumnSearchProps('name'),
      },
     
     
    ];
    return <Table columns={columns} dataSource={data} />;
  }
}

ReactDOM.render(<App />, mountNode);
Ниже приведен код для таблицы проектирования Ant с фильтрацией объекта с использованием поля ввода, но я хочу, чтобы он преобразовал его в поле даты-выбора antd вместо поля ввода, но не понял, как его преобразовать.

1 Ответ

0 голосов
/ 20 апреля 2020

Вы можете использовать что-то подобное для отображения DatePicker вместо searchInput.

<div style={{ padding, width }}>
  <DatePicker.RangePicker
    autoFocus={autoFocus}
    onChange={handleChange}
    placeholder={placeholder}
    value={value}
    format={format}
    style={{ marginBottom: 8 }}
  />
  <Button
    type="primary"
    role="search"
    onClick={handleSearch}
    style={{ width: btnWidth }}
    icon={<SearchOutlined />}
    size="small"
  >
    {label[0]}
  </Button>
  <Button
    role="reset"
    style={{ width: btnWidth, marginLeft }}
    onClick={handleClear}
    size="small"
  >
    {label[1]}
  </Button>
</div>
...