0

我正在尝试使用逗号分隔符以印度数字格式显示表格中的财务数据。我正在使用react-data-table-component在我的网页中创建表格。

const columns = [
  {
    name: "Year",
    selector: "Year",
    sortable: true
  },
  {
    name: "India's GDP in crore",
    selector: "India's GDP* in crore",
    sortable: true,
    right:true
  },
  {
    name: "Growth rate in per cent",
    selector: "Growth rate in per cent",
    sortable: true,
    right: true
  },
  {
    name: "State's GSDP in crore",
    selector: "State's GSDP* in crore",
    sortable: true,
    right: true
  },
  {
    name: "Growth rate in percent(1)",
    selector: "Growth rate in percent(1)",
    sortable: true,
    right: true
  },
];


const Table = () => {
  
  const ctx = useContext(MyContext)

  return (
    <div className="App">
      <Card>
        <DataTable
          title="Table1.1"
          columns={columns}
          data={ctx.reportData.Tables2.Table1}
          defaultSortField="title"
          sortIcon={<SortIcon />}
                  />
      </Card>
    </div>
  );
}

我传递给 DataTable 组件的数据参数的表数组是这样的 -

"Table1":[
            {
                "Year":"2015-16",
                "India's GDP* in crore":13771875,
                "Growth rate in per cent":10.46,
                "State's GSDP* in crore":1045168,
                "Growth rate in per cent__1":14.36
            },
            {
                "Year":"2016-17",
                "India's GDP* in crore":15391665,
                "Growth rate in per cent":11.76,
                "State's GSDP* in crore":1209136,
                "Growth rate in per cent__1":15.69
            },
            {
                "Year":"2017-18",
                "India's GDP* in crore":17098304,
                "Growth rate in per cent":11.09,
                "State's GSDP* in crore":1357579,
                "Growth rate in per cent__1":12.28
            },
            {
                "Year":"2018-19",
                "India's GDP* in crore":18971234,
                "Growth rate in per cent":10.95,
                "State's GSDP* in crore":1544399,
                "Growth rate in per cent__1":13.76
            },
            {
                "Year":"2019-20",
                "India's GDP* in crore":20442233,
                "Growth rate in per cent":7.75,
                "State's GSDP* in crore":1699115,
                "Growth rate in per cent__1":10.02
            }
        ]

如何以逗号分隔的格式显示表格中的数值?如果您需要更多详细信息,请告诉我。

4

1 回答 1

0

我找到了解决方案。使用 Localestring 将数字转换为逗号分隔的数字。

cell: data => data["India's GDP* in crore"].toLocaleString()

于 2021-06-09T14:55:09.970 回答