首页 > 解决方案 > React.js material-ui:用逗号屏蔽时是否可以对数量进行排序?

问题描述

我有一个包含一Total Amount列的材料表

在我添加逗号屏蔽之前,此列上的排序有效,因为有例如 1,000.00

material-table是否可以修改内置的升序/降序排序以使用屏蔽量?

谢谢

请参阅编辑。

TIA

标签: reactjs

解决方案


是否可以修改材料表的升序/降序的内置排序以使用屏蔽量?

是的,有可能。您需要使用自定义排序。使用customSort列数组中的方法来传递为您排序的函数。

<MaterialTable
      title="Custom Filtering Algorithm Preview"
      columns={[
        {
          title: 'Name', 
          field: 'name',
          customSort: (a, b) => a.name.length - b.name.length
        },
        { title: 'Surname', field: 'surname' },
        { title: 'Birth Year', field: 'birthYear', type: 'numeric' },

更多信息在这里https://material-table.com/#/docs/features/sorting

在你的情况下

{
  title: "Total Amount",
  field: "totalAmount",
  filtering: false,
  customSort: (a, b) => { ... write your sort logic here}
},

推荐阅读