gpt4 book ai didi

reactjs - Material-UI DataGrid 列单元格中的线性进度条

转载 作者:行者123 更新时间:2023-12-05 01:57:09 32 4
gpt4 key购买 nike

我想添加一列,如填充数量

I would like to add a column like Filled Quantity

但我无法从文档中弄清楚如何做到这一点,我觉得在设置列时我必须使用 renderCell 但我看不到如何完成它。

https://mui.com/components/data-grid/demo/

https://mui.com/components/data-grid/columns/

最佳答案

您可以从演示中复制条形渲染器 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)} />;
}

Usage

{
field: "filledQuantity",
headerName: "Filled Quantity",
renderCell: renderProgress,
type: "number",
width: 120
}

现场演示

Codesandbox Demo

关于reactjs - Material-UI DataGrid 列单元格中的线性进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69467236/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com