How to realize the search function of ant design pro table?

problem description

I"m using local mock test data, and I see that the table search function in the official example is available, but after making corresponding changes, I find that the search function is invalid. So I want to ask Daniel

the environmental background of the problems and what methods you have tried

clipboard.png
these are official examples. Click the query button to display the matching data in the table

related codes

/ / Please paste the code text below (do not replace the code with pictures)

  handleSearch = e => {
    e.preventDefault();

    const { dispatch, form } = this.props;

    form.validateFields((err, fieldsValue) => {
      if (err) return;

      const values = {
        ...fieldsValue,
        updatedAt: fieldsValue.updatedAt && fieldsValue.updatedAt.valueOf(),
      };

      this.setState({
        formValues: values,
      });
      dispatch({
        type: "rule/fetch",
        payload: values,
      });
    });
  };

I can find the corresponding request method in the corresponding model and service, but cannot find the logic of query processing

what result do you expect? What is the error message actually seen?

Aug.30,2021

ant-design-pro/mock/rule.js

function getRule(req, res, u) {
  let url = u;
  if (!url || Object.prototype.toString.call(url) !== '[object String]') {
    url = req.url; // eslint-disable-line
  }

  const params = parse(url, true).query;

  let dataSource = tableListDataSource;

  if (params.sorter) {
    const s = params.sorter.split('_');
    dataSource = dataSource.sort((prev, next) => {
      if (s[1] === 'descend') {
        return next[s[0]] - prev[s[0]];
      }
      return prev[s[0]] - next[s[0]];
    });
  }

  if (params.status) {
    const status = params.status.split(',');
    let filterDataSource = [];
    status.forEach(s => {
      filterDataSource = filterDataSource.concat(
        dataSource.filter(data => parseInt(data.status, 10) === parseInt(s[0], 10))
      );
    });
    dataSource = filterDataSource;
  }

  if (params.name) {
    dataSource = dataSource.filter(data => data.name.indexOf(params.name) > -1);
  }

  let pageSize = 10;
  if (params.pageSize) {
    pageSize = params.pageSize * 1;
  }

  const result = {
    list: dataSource,
    pagination: {
      total: dataSource.length,
      pageSize,
      current: parseInt(params.currentPage, 10) || 1,
    },
  };

  return res.json(result);
}

whether the query or filter of the form has the same meaning, it means that Filter drops unqualified data in dataSource

Menu