简体   繁体   English

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

[英]Why is the ag-grid filter comparator not executing?

I'm currently on Angular version 10.2 and ag-grid version 25.3.0我目前使用的是 Angular 10.2 版和ag-grid 25.3.0 版

After following the Date Column Custom Filter documentation for ag-grid here , I've decided to apply it to a number column and modify it a bit.在遵循此处的ag-grid 的日期列自定义过滤器文档之后,我决定将其应用于数字列并对其进行一些修改。 Basically, if the user filters by a number less than 0, it should multiple both the filter and the cell value by 100 and compare.基本上,如果用户按小于 0 的数字进行过滤,则应将过滤器和单元格值乘以 100 并进行比较。 If not, then compare the values normally.如果不是,则正常比较这些值。 My specific column definition is as follows:我的具体列定义如下:

{
  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,
  }
},

The default column definitions also have sortable, filter and resizable all set to true .默认列定义也将 sortable、filter 和 resizable 都设置为true

My problem is that the comparator function is not even triggering.我的问题是比较器功能甚至没有触发。 There is no console logs in the console even though it's the first line in the comparator function.控制台中没有控制台日志,即使它是比较器函数中的第一行。 I've checked ag-grid's GitHub issues and other issues on StackOverflow with no success.我在 StackOverflow 上检查了 ag-grid 的 GitHub 问题和其他问题,但没有成功。

There have been a few Stackoverflow issues but those have been with the Column value Comparator and not the comparator inside the filterParams .有一些 Stackoverflow 问题,但这些问题与 Column value Comparator 而不是filterParams的比较器有关。 Any help would be appreciated.任何帮助,将不胜感激。 Thanks!谢谢!

If you want to use agNumberComparator you can check the below document.如果您想使用 agNumberComparator,您可以查看以下文档。 comparator is not a filterparams attribute on here.比较器不是这里的 filterparams 属性。 I think your comparator function is not triggered becouse of this.我认为因此不会触发您的比较器功能。 https://www.ag-grid.com/angular-grid/filter-number/#custom-number-support https://www.ag-grid.com/angular-grid/filter-number/#custom-number-support

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM