【问题标题】:AG Grid - Sorting a column with key and not ValueAG Grid - 使用键而不是值对列进行排序
【发布时间】:2020-02-26 11:05:48
【问题描述】:

我正在寻找机会用键而不是显示的值对列进行排序,但我找不到执行此操作的方法。

我正在加载这样的数据:

[{key: 1, name: 'Microsoft'}, {key: 2, name: 'Apple'}, {key: 3, 'IBM'}]

现在列的排序是这样的:

'Apple'
'IBM'
'Microsoft'

但我想要这样的排序,并且网格中没有“键”列:

'Microsoft'
'Apple'
'IBM'

我想我需要使用自定义排序,但不知道如何开始。

任何帮助都是有用的。

提前致谢。

【问题讨论】:

标签: ag-grid


【解决方案1】:

columnDefs 中添加comparator 喜欢 -

var columnDefs = [
  {
    headerName: 'Company', 
    field: 'name', 
    comparator: (value1, value2, node1, node2) => node1.data.key - node2.data.key
  }
];

这是 Plunker:Custom Sorting ag-Grid

【讨论】:

    猜你喜欢
    • 2016-06-19
    • 2021-12-16
    • 2020-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-13
    • 2019-12-03
    相关资源
    最近更新 更多