1

I am having this in my app.component.ts

numberFormatter(params:number) : String {
    return params.toFixed(3).toString();
  }

columnDefs = [
   {headerName: 'Month', field: 'month', valueFormatter: this.numberFormatter, },
   {headerName: 'Values', field: 'value', valueFormatter: this.numberFormatter, }, 
]

rowData: any[] = [
{ month: 0, value: 5 + (Math.random( ) - 0.5) * 2 },
{ month: 1, value: 5 + (Math.random( ) - 0.5) * 2 },
{ month: 2, value: 5 + (Math.random( ) - 0.5) * 2 },
...
]

In my app.component.html:

<div>
    <ag-grid-angular
        [rowData]="rowData" 
        [columnDefs]="columnDefs">
    </ag-grid-angular>
</div>

All I get is the error: error TS2322: Type '{ headerName: string; field: string; valueFormatter: (params: any) => String; }[]' is not assignable to type '(ColDef | ColGroupDef)[]'.

I tried to change numberFormatter to:

  numberFormatter(params:any) : String {
    return Number(params).toFixed(3).toString();
  }

It does not work either.

xymzh
  • 63
  • 5
  • Also, you should probably be using string primitives instead of String objects. And Number(parms) looks dangerous, given that the type of params is 'any'. If params is a number, then type it as a number (primitive, not a Number object). You should rarely, if ever need to use either String or Number. See, for example, https://stackoverflow.com/questions/14727044/what-is-the-difference-between-types-string-and-string – GreyBeardedGeek May 06 '23 at 22:30

1 Answers1

1

Use params.value Instead of params

Example

function bracketsFormatter(params: ValueFormatterParams) {
  return '(' + params.value + ')';
}
jyangca
  • 582
  • 2
  • 11