REACT-如何在Mui数据表中为整数值添加逗号分隔符



在我的mui数据表中,我有一个整数形式的工资列,我想在其中添加逗号分隔符,例如100000-->100000,我试过了,但我的方法不起作用

我的组件看起来像这个

class EmployeeTable extends Component {
const columns = [
{ name: "name", label: "Name" },
{ name: "phone_no", label: "Contact" },
{ name: "email", label: "Email" },
{ name: "department", label: "Department" },
{ name: "job_title", label: "Title" },
{ name: "salary", label: "Salary" }, <--- My integer Field
{ name: "date_employed", label: "Date Employed" },

];
const options = {
filterType: "checkbox",
rowsPerPage: 5,
rowsPerPageOptions: [5, 10, 15, 20],
downloadOptions: { filename: "InvoiceData.csv", separator: "," },
elevation: 6,
};
return (
<MUIDataTable
title={"Employees Records"}
data={this.state.employeesDetail}
columns={columns}
options={options}
/>

);
}
}
export default EmployeeTable;

使用customBodyRender。参考本

const columns = [
{ name: "name", label: "Name" },
{ name: "phone_no", label: "Contact" },
{ name: "email", label: "Email" },
{ name: "department", label: "Department" },
{ name: "job_title", label: "Title" },
{
name: "salary", label: "Salary",
options: {
customBodyRender: function (value, tableMeta, updateValue) {
return new Intl.NumberFormat().format(value)
}
}
},
{ name: "date_employed", label: "Date Employed" },
];

最新更新