[英]React Material-Table - How can I add commas between cell that is rendered from fetched array?
I'm using Material Table for managing workstations.我正在使用 Material Table 来管理工作站。 Some of the data I receive are arrays, they are automatically iterated and displayed in cell but without commas.
我收到的一些数据是 arrays,它们会自动迭代并显示在单元格中但没有逗号。
Current behavior picture当前行为图片
What I'm trying to achieve我想要达到的目标
I feel like overriding whole cell component is overkill and I would like to avoid modyfing fetched array.我觉得覆盖整个单元格组件是矫枉过正的,我想避免修改获取的数组。 Is there is any way that I can modify that iteration done by Material Table at "MTableCell" component?
有什么方法可以修改“MTableCell”组件中 Material Table 完成的迭代? Or maybe there is some smarter way of doing this?
或者也许有一些更聪明的方法来做到这一点?
Assuming attribs
is your data as array (as shown in the picture):假设
attribs
是你的数据作为数组(如图所示):
const attribs = ['ATTRIBUTE1', 'ATTRIBUTE2', 'ATTRIBUTE3'];
You can use reduce
to convert that to a comma-separated string:您可以使用
reduce
将其转换为逗号分隔的字符串:
const separated = attribs.reduce((prev, current) => `${prev},${current}`);
And then feed that into the material table cell.然后将其输入材料表单元格。 You can check a simple example here: https://codesandbox.io/s/basictable-material-demo-forked-19c9z?file=/demo.js
你可以在这里查看一个简单的例子: https://codesandbox.io/s/basictable-material-demo-forked-19c9z?file=/demo.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.