更改材料表反应中的“操作”样式

时间:2020-01-17 04:16:49

标签: reactjs material-table

我一直在一个项目中使用材料表。

虽然我可以更改用户定义的列的样式(字体大小,颜色),但不能对“操作”列进行更改。

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

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

请从以下示例:

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

2 个答案:

答案 0 :(得分:7)

对于分页,应覆盖分页组件。issuedocumentation

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


看看这个codesandbox,会有所帮助。

答案 1 :(得分:0)

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

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