reactjs - Material 表搜索不适用于自定义列

标签 reactjs material-table

各位,

我有一个垫表,其中自定义列为“Items”,它可以有多个值。 我可以将其渲染为逗号分隔值,但是为了更好的外观和感觉,我将每个项目渲染为芯片。

现在的问题是 mat 表默认搜索不适用于该字段。

任何帮助将不胜感激。

enter image description here

import React, { Fragment, useState } from "react";
import MaterialTable from "material-table";
import { Box, makeStyles, Chip } from "@material-ui/core";

const useStyles = makeStyles((theme) => ({
    chip: {
      margin: 2
    },
    noLabel: {
      marginTop: theme.spacing(3)
    },
  }));
  

const originalData = [
  {
    id: "1",
    productName: "Meat",
    items: [
        {id : 1, name : "chicken"},
        {id : 2, name : "pork" },
        {id : 3, name : "lamb" }
        ]
    
  },
  {
    id: "2",
    productName: "Vegetables",
    items: [
        {id : 1, name : "Okra"},
        {id : 2, name : "Pumpkin" },
        {id : 3, name : "Onion" }
        ]
    
  },

];

export default function MatTableTest(props) {
  const [data, setData] = useState(originalData);
  const classes = useStyles();
  const tableColumns = [
    { title: "id", field: "id", editable : "never" },
    { title: "Product Name", field: "productName" , editable : "never" },
    { title: "Item", field: "items", editable : "never", 
    render: rowData => {
        return (
          <Box className="box" id="style-7">
            { rowData.items.map((exprt) => <Chip
              key={exprt.id}
              label={exprt.name}
              className={classes.chip}
            />)}
          </Box>
        );
      }
},

    
  ];

  return (
    <Fragment>
      <MaterialTable
        columns={tableColumns}
        data={data}
        title="Material Table - Custom Colum  Search"
      />
    </Fragment>
  );
}


最佳答案

有一个名为 customFilterAndSearch 的属性,您可以在其中定义自定义过滤器函数。您可以在其中定义要匹配的行数据。 Here is an example来自 Github 存储库中创建的问题。

关于reactjs - Material 表搜索不适用于自定义列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66523045/

相关文章:

javascript - 为 material-ui IconButton 设置悬停样式

reactjs - 如何使用 ant design 动态生成选择组件的选项

reactjs - 在 ReactJS 中使用状态更新模拟多个获取调用

javascript - Material 表可编辑 : Making all rows editable at once

reactjs - 如何在使用reactjs拖动时读取 Material 表列标题数组

reactjs - 如何使 React js Material-UI 表具有响应性并使其具有相等的列间距?

javascript - Moment.js 处理德语 Dezember 和 Januar 的方式不同

javascript - 使用 Redux 处理异步文件上传

reactjs - 如何在行中放置自定义按钮标签,使用 material-table 和 typeScript,他希望收到的 Prop 是什么?

reactjs - react Material 表操作按钮标记覆盖多个操作