在 material-table 中更改 "Actions" 的样式 react

Changing the style of "Actions" in material-table react

我一直在我的一个项目中使用 material-table。

虽然我可以更改用户定义列的样式(字体大小、颜色),但我无法对 "Actions" 列执行此操作。

我对更改字体大小特别感兴趣。

与分页相同的问题:我需要更改其字体大小,但似乎没有可用的选项。

请举个例子:

https://material-ui.com/components/tables/#complementary-projects

对于分页,您应该覆盖分页组件。issue, documentation

const useStyles = makeStyles({
  root: {
    backgroundColor: "blue",
    color: "green"
  },
  toolbar: {
    backgroundColor: "white"
  },
  caption: {
    color: "red",
    fontSize: "20px"
  },
  selectIcon: {
    color: "green"
  },
  select: {
    color: "green",
    fontSize: "20px"
  },
  actions: {
    color: "blue"
  }
});
...
 <MaterialTable
    .....
    components={{
            Pagination: props => (
              console.log(props),
              (
                <TablePagination
             {props.labelDisplayedRows(row)}</div>}
                  component="div"
                  colSpan={props.colSpan}
                  count={props.count}
                  rowsPerPage={props.rowsPerPage}
                  page={props.page}
                  onChangePage={props.onChangePage}
                  onChangeRowsPerPage={this.onChangeRowsPerPage}
                  classes={{
                    root: classes.root,
                    toolbar: classes.toolbar,
                    caption: classes.caption,
                    selectIcon: classes.selectIcon,
                    select: classes.select,
                    actions: classes.actions
                  }}
                />
              )
            )
          }}

对于 "Actions" 列,我使用了 actions 属性

 actions={[
        {
          icon: "save",
          iconProps: { style: { fontSize: "14px", color: "green" } },
          tooltip: "Save User",
          onClick: (event, rowData) => alert("You saved " + rowData.name)
        }
      ]}


看看这个 codesandbox,会有帮助。

如果您想坚持使用用户定义的主题,请使用 icon api of material-ui 中的道具。

actions={[
    {
      icon: "save",
      iconProps: {  fontSize: "small", color: "primary"  },
      tooltip: "Save User",
      onClick: (event, rowData) => alert("You saved " + rowData.name)
    }
  ]}