React Material - MUIDataTable - 如何在列 header 中添加内容

React Material - MUIDataTable - how to add content in column header

我在我的 React 应用程序中使用:

import MUIDataTable from "mui-datatables";

我想在最后一列中添加一些按钮 header(而不是列名称):

 <MUIDataTable
            data={data}
            columns={columns}
            options={options}
        >
        </MUIDataTable>

其中列:

export const columns = [
    {
        name: "name",
        label: "Nazwa",
        options: {
            filter: true,
            sort: true,
        }
    },
    {
        name: "productNumber",
        label: "Numer",
        options: {
            filter: true,
            sort: true,
        }
    }, (...)

怎么做?是否可以?我找不到任何东西

您可以为列定义自定义主体。您可以像这样添加一列:

{
  name: "Age",
  options: {
     filter: false,
     customBodyRender: (value, tableMeta, updateValue) => (
        <FormControlLabel
          control={<TextField value={value || ''} type='number' />}
          onChange={event => updateValue(event.target.value)}
        />
     )
  }
}

您需要使用customHeadRender

const columns = [
    {
        name: "id",
        label: "Id",
        options: {
            filter: false,
        }
    },
    {
        name: "subject",
        label: "Subject",
        options: {
            filter: true,
            sort: false,
        }
    },
    {
        name: "button",
        options: {
            customHeadRender: ({index, ...column}) => {
                return (
                    <Button key={index}>
                        Click
                    </Button>
                )
            }
        }
    }
];