Material-table: How to style specific cell ?

Created on 2 Jun 2019  路  2Comments  路  Source: mbrn/material-table

I want to style cells that custom validate false (for example value less then zero) in red. All others should remain in default style.

How can i achieve this ?
I tried with
optionsData=
{
rowStyle: rowData => ({
backgroundColor: (rowData.price<0) ? 'red' : 'green'
})
}

This will highlight the complete row red. I just want the cells that have condition false to be red.

Can you help me with this issue ?

help wanted

Most helpful comment

Hi @AlexandruPavel8

You can use cellStyle inside you column definition.

{
title: 'title',
field: 'field',
cellStyle: rowData => ({ // your style. })
}

All 2 comments

Hi @AlexandruPavel8

You can use cellStyle inside you column definition.

{
title: 'title',
field: 'field',
cellStyle: rowData => ({ // your style. })
}

@mbrn but If I want to change all row style?
How can I do this?

components={{                       
                    Row: rowProps => <MTableBodyRow {...rowProps} className={MyFUNCTION} />
                } ,                 
                .....
            }

In the previous version of lib, I've used something like this, but it doesn't work in the actual version.

Was this page helpful?
0 / 5 - 0 ratings