为反应材料表应用特定主题

问题描述 投票:2回答:1

我正在尝试将react material-table(https://github.com/mbrn/material-table)与我的项目集成。

  1. 我想更新样式/主题。

我用了类似的东西。

<MaterialTable options={{
                        rowStyle: x => {
                            if ( x.id % 2 ) {
                            return { backgroundColor: "#f2f2f2" }
                            }
                        },
                        'headerStyle' : {
                            backgroundColor: 'red',
                            color: theme.palette.common.white
                        }
                        }}
    columns={columns}
    data={data}
    title="New Table"
/>

但是我希望有一个通用的样式和主题

const CustomTableCell = withStyles(theme => ({
  head: {
    backgroundColor: theme.palette.common.black,
    color: theme.palette.common.white,
  },
  body: {
    fontSize: 14,
  },
}))(TableCell);

基本上我想要像CustomMaterialTable这样的东西,这只是我的主题/风格。

  1. 条带化表行。在上面的代码片段中,我使用了一个逻辑来创建条带行。
if ( x.id % 2 ) {
    return { backgroundColor: "#f2f2f2" }
}

由于我的表将进行排序,我希望它在自动生成的行id上而不是x.id(其中x是我的数据)。

  1. 我想根据语言选择(动态)使用多种语言的rtl和文本。
reactjs material-ui material-table
1个回答
3
投票
  1. 您可以覆盖组件。看看例子:https://mbrn.github.io/material-table/#/docz-examples-10-example-component-overriding
  2. 你能试试x.tableData.id而不是x.id吗?
  3. 你应该使用带有方向的材料-ui主题(ltr或rtl):https://material-ui.com/customization/themes/
© www.soinside.com 2019 - 2024. All rights reserved.