Kla*_*aus 4 javascript reactjs material-ui mui-datatable
我使用 React.js 和MUI-Datatables创建了一个简单的表:
import MUIDataTable from "mui-datatables";
const columns = ["Name", "Company", "City", "State"];
const data = [
["Joe James", "Test Corp", "Yonkers", "NY"],
["John Walsh", "Test Corp", "Hartford", "CT"],
["Bob Herm", "Test Corp", "Tampa", "FL"],
["James Houston", "Test Corp", "Dallas", "TX"],
];
const options = {
filterType: 'checkbox',
};
<MUIDataTable
title={"Employee List"}
data={data}
columns={columns}
options={options}
/>
Run Code Online (Sandbox Code Playgroud)
如何将自定义 CSS 类添加到表格内的单行。假设我希望 John Walsh 的第二行具有绿色背景色。
更新:
使用customRowRender允许设置特定行的样式,但我对解决方案仍然不是 100% 满意,因为诸如可选行之类的某些功能不再开箱即用:
const options = {
filterType: "checkbox",
customRowRender: (data, dataIndex, rowIndex) => {
let style = {};
if (data[0] === "John Walsh") {
style.backgroundColor = "green";
}
return (
<TableRow style={style}>
<TableCell />
<TableCell>
<Typography>{data[0]}</Typography>
</TableCell>
<TableCell>
<Typography>{data[1]}</Typography>
</TableCell>
<TableCell>
<Typography>{data[2]}</Typography>
</TableCell>
<TableCell>
<Typography>{data[3]}</Typography>
</TableCell>
</TableRow>
);
}
};
Run Code Online (Sandbox Code Playgroud)
小智 7
干得好。
setRowProps: row => {
if (row[0] === "New") {
return {
style: { background: "snow" }
};
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5303 次 |
| 最近记录: |