我想添加一个像Filled这样的列
但是我不能从文档中弄清楚如何做到这一点,我觉得在设置专栏时我必须使用renderCell
,但我看不到如何完成它。
发布于 2021-10-06 06:16:34
您可以从演示here中复制条形图渲染器
const defaultTheme = createTheme();
const useStyles = makeStyles(
(theme) =>
createStyles({
root: {
border: `1px solid ${theme.palette.divider}`,
position: "relative",
overflow: "hidden",
width: "100%",
height: 26,
borderRadius: 2
},
value: {
position: "absolute",
lineHeight: "24px",
width: "100%",
display: "flex",
justifyContent: "center"
},
bar: {
height: "100%",
"&.low": {
backgroundColor: "#f44336"
},
"&.medium": {
backgroundColor: "#efbb5aa3"
},
"&.high": {
backgroundColor: "#088208a3"
}
}
}),
{ defaultTheme }
);
const ProgressBar = React.memo(function ProgressBar(props) {
const { value } = props;
const valueInPercent = value * 100;
const classes = useStyles();
return (
<div className={classes.root}>
<div
className={classes.value}
>{`${valueInPercent.toLocaleString()} %`}</div>
<div
className={clsx(classes.bar, {
low: valueInPercent < 30,
medium: valueInPercent >= 30 && valueInPercent <= 70,
high: valueInPercent > 70
})}
style={{ maxWidth: `${valueInPercent}%` }}
/>
</div>
);
});
export function renderProgress(params) {
return <ProgressBar value={Number(params.value)} />;
}
{
field: "filledQuantity",
headerName: "Filled Quantity",
renderCell: renderProgress,
type: "number",
width: 120
}
实时演示
https://stackoverflow.com/questions/69467236
复制相似问题