为什么 ag-grid 过滤器比较器不执行?

Why is the ag-grid filter comparator not executing?

我目前使用 Angular 版本 10.2 和 ag-grid 版本 25.3.0

遵循 ag-grid here 的日期列自定义筛选器文档后,我决定将其应用于数字列并稍作修改。基本上,如果用户按小于 0 的数字进行过滤,则应将过滤器和单元格值乘以 100 并进行比较。如果不是,则正常比较值。我具体的列定义如下:

{
  field: 'roi',
  headerName: 'ROI',
  valueGetter: this.calculateROI.bind(this),
  filter: 'agNumberColumnFilter',
  filterParams: {
    comparator: function(filterValue: number, cellValue: number) {
      console.log(filterValue);
      if (filterValue < 0) {
        filterValue *= 100;
        cellValue *= 100;
      }

      if (cellValue < filterValue) return -1;
      if (cellValue === filterValue) return 0;
      return 1;
    }
  },
  valueFormatter: this.percentFormat.bind(this),
  cellClassRules: {
    'cell-failure': (params: ValueFormatterParams) => params.value < 0,
    'cell-success': (params: ValueFormatterParams) => params.value > 0,
    'cell-even': (params: ValueFormatterParams) => params.value === 0,
  }
},

默认列定义也将可排序、筛选和调整大小都设置为 true

我的问题是比较器功能甚至没有触发。控制台中没有控制台日志,即使它是比较函数中的第一行。我已经检查了 ag-grid 的 GitHub 问题和 Whosebug 上的其他问题,但没有成功。

有一些 Whosebug 问题,但这些问题与列值比较器有关,而不是 filterParams 内的比较器。任何帮助,将不胜感激。谢谢!

如果你想使用 agNumberComparator 你可以查看下面的文档。 comparator 不是此处的 filterparams 属性。我认为您的比较器功能不会因此而触发。 https://www.ag-grid.com/angular-grid/filter-number/#custom-number-support