【问题标题】:How to customise content in material-table (React)?如何自定义材料表(React)中的内容?
【发布时间】:2020-05-07 22:41:18
【问题描述】:

我想在每个项目前添加一个图标,对应于一列中的数据。目前,我只是使用 JS 数组来显示静态数据,但无法自定义。

立即使用:

<MaterialTable
title="Title"
columns={this.state.columns}
data={newDataTable}
options={{
  selection: true
}}
options={{
  search: false,
  sorting: true
}}
actions={[
  {
    icon: () => <Checkbox />,
    tooltip: 'checkbox'
  },
  {
    icon: () => <InfoIcon />,
    tooltip: 'info',
    onClick: (event, item) => {
      this.setState({
        isOpen: true,
        selectedItem: item
      });
    }
  }
]}

/>

【问题讨论】:

    标签: reactjs material-ui material-table mui-datatable


    【解决方案1】:

    我假设您使用的是:https://github.com/mbrn/material-table

    在将数据传递给表格之前,您可以添加如下图标:

    const newData = newDataTable.map((value) => ({...value, firstColumn: <SomeIcon />}));
    

    并添加一列:{ title: "", field: "firstColumn" }"

    【讨论】:

      猜你喜欢
      • 2020-09-02
      • 2014-05-26
      • 1970-01-01
      • 1970-01-01
      • 2019-04-19
      • 1970-01-01
      • 2019-04-28
      • 2020-05-20
      • 2021-03-08
      相关资源
      最近更新 更多