Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying specific theme for react material-table

I'm trying to integrate react material-table (https://github.com/mbrn/material-table) with my project.

  1. I want to update the styling/theme.

I used something like.

<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"
/>

However I want to have a generic styling and theme like

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

Basically i want to have something like CustomMaterialTable which is nothing but my theme/style.

  1. Striping the table rows. In the above code snippet, I used a logic to have striped rows.
if ( x.id % 2 ) {
    return { backgroundColor: "#f2f2f2" }
}

Since my table will be having sorting, I want the it to be on a auto generated row id rather than x.id (where x is my data).

  1. I want to use rtl and text in multiple languages based on the language selection (dynamic).
like image 432
Shelly Avatar asked Apr 10 '19 11:04

Shelly


People also ask

How do I change my theme in React?

Adding themes with ThemeProvider. ThemeProvider provides our theme to every component within its wrapper via the React Context API. We'll use ThemeProvider to enable theme switching. First, let's import ThemeProvider and then import our Themes from the Theme.


1 Answers

  1. You can overrides components. Look at example: https://mbrn.github.io/material-table/#/docz-examples-10-example-component-overriding

  2. Can you try x.tableData.id instead of x.id, please?

  3. You should use material-ui theme with direction (ltr or rtl): https://material-ui.com/customization/themes/

like image 133
mehmet baran Avatar answered Sep 30 '22 21:09

mehmet baran