使用角度2最新版本

时间:2016-10-21 09:21:58

标签: angular typescript ag-grid

我在我的ag-grid项目中显示货币计算,但我试图以美国货币格式设置货币值(如232,345)。我不知道如何设置ag-grid,任何人都可以帮助解决我的问题。

我尝试过这样编码:

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

谢谢。

2 个答案:

答案 0 :(得分:1)

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 }
      ];

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

答案 1 :(得分:0)

您需要将过滤器更改为currency:'USD':true:'1.2-2'

这会修改过滤器以使用点作为小数点分隔符,并在点后使用2位数。

https://www.ag-grid.com/javascript-grid-column-definitions/index.php处的文档介绍了如何定义列。您已经指定了field参数,现在您还必须添加filter参数,然后似乎不再需要template