简体   繁体   English

React Ant design Table-自定义搜索过滤器

[英]React Ant design Table- Customize the search filter

I am trying to customize the search filter in React Ant design table, typically ant design allows customizable dropdown for search filter, for example .我正在尝试在 React Ant 设计表中自定义搜索过滤器,通常 ant 设计允许搜索过滤器的可自定义下拉列表,例如 But the requirement is to show permanent search boxes under the columns similar to the react table by Tanner , rather than a dropdown.但要求是在类似于Tanner反应表的列下显示永久搜索框,而不是下拉列表。

I tried to pass a ReactNode in title prop for columns, but it creates weird onClick side effects.我试图在列的标题道具中传递一个 ReactNode,但它会产生奇怪的 onClick 副作用。 Is there a way to customize the header?有没有办法自定义标题?

Making it simple, you can create the first row as:简单来说,您可以将第一行创建为:

getFieldsForEachColumn = (columns) => {
const row = {};
columns.forEach((element, index) => {
  if (element.searchable) {
    const inputFieldCell = (
      <Input onChange={(e) => this.handleOnChange(e.target.value, element.title)}/>
    );
    row[Object.keys(data[0])[index + 1]] = inputFieldCell
  } else {
    row[Object.keys(data[0])[index + 1]] = null;
  }
});
return row;

}; };

And then when you are mapping the array data, just push this returned in the started of that array.然后当您映射数组数据时,只需将返回的值推入该数组的开头即可。

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

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