Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React admin 如何有条件地更改datagrid行的背景颜色?_React Admin - Fatal编程技术网

React admin 如何有条件地更改datagrid行的背景颜色?

React admin 如何有条件地更改datagrid行的背景颜色?,react-admin,React Admin,取决于源(记录的)字段值(例如,状态列为“活动”),我希望在Datagrid中使行背景为特定颜色。我该怎么做?感谢您提供的任何示例代码 您可以根据记录自定义datagrid行样式(应用于元素),这要归功于行样式属性,它需要一个函数 例如,如果记录的一个值(如其视图数)超过某个阈值,则允许对整行应用自定义背景 const postRowStyle = (record, index) => ({ backgroundColor: record.nb_views >= 500 ?

取决于源(记录的)字段值(例如,状态列为“活动”),我希望在Datagrid中使行背景为特定颜色。我该怎么做?感谢您提供的任何示例代码

您可以根据记录自定义datagrid行样式(应用于
元素),这要归功于
行样式
属性,它需要一个函数

例如,如果记录的一个值(如其视图数)超过某个阈值,则允许对整行应用自定义背景

const postRowStyle = (record, index) => ({
    backgroundColor: record.nb_views >= 500 ? '#efe' : 'white',
});
export const PostList = (props) => (
    <List {...props}>
        <Datagrid rowStyle={postRowStyle}>
            ...
        </Datagrid>
    </List>
);
constpostrowstyle=(记录、索引)=>({
背景颜色:record.nb_views>=500?“#efe”:“白色”,
});
导出常量PostList=(道具)=>(
...
);

这一点记录在。

适用于我:)