为什么将值格式化程序应用于单元格但显示的值不会更改 ag-grid

Why Value Formatter gets Applied to the Cell but the Displayed Value does Not Change ag-grid

我的 ag-grid 中确实有以下 函数

  ngOnInit(): void {

            this.columnDefs = [
                {
                headerName: 'Header', field: 'quantity',
                valueFormatter: (params) => this.numberFormatter(params),
                }
        ];
   }

  numberFormatter(params){
    console.log(params.value);
    return '$'+params.value;
  }

无论 numberFormatter() 函数中对当前值进行什么更改,[=33 中都不会显示任何更改=].

但是更改是可见的,并且 numberFormatter() 方法中正确返回

我错过了什么?

似乎您的数据未显示(或您的数据中不存在字段 quantity

您必须正确定义它,它应该按预期工作

此处完全相同DEMO有效

you don't need to execute anonymous function in valueFormatter definition, you can just assign the function

valueFormatter: this.numberFormatter.bind(this)

it doesn't affect on result