简体   繁体   English

React Material-Table - 如何在从获取的数组呈现的单元格之间添加逗号?

[英]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.

相关问题 React Material-table - 无法访问对象的字段(在对象数组内) - React Material-table - cannot access fields of objects (inside an array of objects) 如何在数组中的数字之间添加逗号? - How can I adding commas between the numbers in array? 反应:当从 API 端点获取数据数组的某些元素时,它们不会被渲染 - React: some elements of a data array are not rendered when they are fetched from an API endpoint 如何在反应表中显示从 API 获取的数据? - How to display fetched data from API in react-table? Laravel在数组元素之间添加逗号 - Laravel add commas between array elements 如何在Laravel中为从数据库中获取的数组数据增加限制 - How to add limit to array data fetched from database in laravel 如何在单元格数组中添加矩阵? - How can I add matrices inside a cell array? 如何删除列表元素之间的逗号? - How can I remove the commas between a list's elements? 角度材料数据表。 如何放置动态表(数组中的数组)? - Angular Material datatable. How can I put dynamic table (array in array)? 如何将文件从 pandas dataframe read_csv 转换为 numpy 数组,其中逗号和“numpy.ndarray”类型之间? - How do I convert a file from a pandas dataframe read_csv into a numpy array with commas in between and 'numpy.ndarray' type?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM