1

I'm displaying currency calculations in my ag-grid project but i'm trying to set the currency value in a US currency format (like 232,345). I have no idea how to set that in ag-grid can anyone please help to resolve my issue.

I tried coding like these:

{
     cellRendererFramework: { template: '{{params.firstSalary | currency}}'},
     headerName: 'First Salary', field: 'firstSalary', width: 130, 
},

Thank You.

Nunna Suma
  • 469
  • 1
  • 11
  • 23

2 Answers2

2

CurrencyCellRendererUSD(params: any) {
        var inrFormat = new Intl.NumberFormat('en-US', {
          style: 'currency',
          currency: 'USD',
          minimumFractionDigits: 2
        });
        return inrFormat.format(params.value);
      }

      columnDefs = [
        { headerName: 'A/c No', field: 'accountNo', width: 100 },
        { headerName: 'A/c Name', field: 'accountName' },
        { headerName: 'A/c Balance in USD', field: 'accountBalance', cellRenderer: this.CurrencyCellRendererUSD }
      ];

      rowData = [
        { accountNo: '1', accountName: 'Prajakta', accountBalance: 1000 },
        { accountNo: '2', accountName: 'Sanketa', accountBalance: 10000 },
        { accountNo: '3', accountName: 'Harsha', accountBalance: 100000 },
        { accountNo: '4', accountName: 'Janhavee', accountBalance: 1000000 },
        { accountNo: '5', accountName: 'Vignesh', accountBalance: 10000000 },
        { accountNo: '6', accountName: 'Upesh', accountBalance: 100000000 }
      ];

Output

Prajpk
  • 29
  • 9
0

You need to change the filter to currency:'USD':true:'1.2-2'.

This modifies the filter to use a dot as the decimal separator and use 2 digits after the dot.

The documentation at https://www.ag-grid.com/javascript-grid-column-definitions/index.php shows you how to define a column. You already specified the field paramter, now you must also add the filter parameter, and then it seems that the template is no longer necessary.

Roy Dictus
  • 32,551
  • 8
  • 60
  • 76