Changing the style of “Actions” in material-table react

梦想与她 提交于 2020-07-09 12:10:28

问题


I have been using material-table in one of my projects.

While I am able to change the style ( font-size, color) of the user defined columns, I am not able to do so for the "Actions" column.

I am specially interested in changing the font-size.

Same issue with the pagenation: I need to change its font-size however it seems there is no option available.

Please take an example from :

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


回答1:


For pagination, you should override pagination component.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
                  }}
                />
              )
            )
          }}

For for the "Actions" column, I've used actions property

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


have look at this codesandbox,would be helpful.



来源:https://stackoverflow.com/questions/59781114/changing-the-style-of-actions-in-material-table-react

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!