REACT - 如何在 Mui-Datatables 中将逗号分隔符添加到整数值

Posted

技术标签:

【中文标题】REACT - 如何在 Mui-Datatables 中将逗号分隔符添加到整数值【英文标题】:REACT - How to add comma separator to integer value in Mui-Datatables 【发布时间】:2020-11-20 14:09:43 【问题描述】:

在我的 mui-datatables 中,我有一个整数形式的薪水列,我想在其中添加逗号分隔符,例如 100000 --> 100,000,我尝试过,但我的方法没有工作

我的组件看起来像这样

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;

【问题讨论】:

【参考方案1】:

使用 customBodyRender。参考this

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" ,

];

【讨论】:

以上是关于REACT - 如何在 Mui-Datatables 中将逗号分隔符添加到整数值的主要内容,如果未能解决你的问题,请参考以下文章

如何摆脱表格顶部的 MUI-Datatable“选定行”面板

如何在事件处理程序的 mui-datatable 中使用 material-ui 菜单

如何使用 responsive="scroll" 将高度设置为 mui-datatable

搜索在 mui-datatable、reactjs 中不起作用?

javascript Mui-Datatable,列上有过滤器,在顶部显示过滤属性。

mui-datatable 服务器端渲染“WebpackError:ReferenceError:未定义窗口”