Ag-Grid: formatting numbers, for example: 123456.78 to 123.457

I have huge sets of numerical data. this should be represented as a comma separated value. For example. 123456.78to be displayed as 123,457using the Ag-Grid. Please help me achieve this.

+4
source share
3 answers
{
         headerName: 'Salary', field: 'sal'
        cellRenderer: this.CurrencyCellRenderer
       }

private CurrencyCellRenderer(params:any) {

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

Similarly, we can mention in Angular2 Typescript code.

+3
source

According to the cell processing flow documentation ( here ), you can use colDef.valueFormatter, for example:

var columnDefs = [
    {headerName: "Number", field: "number"},
    {headerName: "Formatted", field: "number", valueFormatter: currencyFormatter}
];

function currencyFormatter(params) {
    return '£' + formatNumber(params.value);
}

function formatNumber(number) {
    // this puts commas into the number eg 1000 goes to 1,000,
    // i pulled this from stack overflow, i have no idea how it works
    return Math.floor(number).toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
}

cellRenderer, , , Formatter . ag-grid :

valueFormatter . cellRenderer , HTML- . , , , valueFormatter, HTML- cellRenderer. , valueFormatter cellRenderer.

+3

, "customcellRenderer", , "cellRenderer" , -

var colDef = {
    name: 'Col Name',
    field' 'Col Field',
    cellRenderer: function(params) {
        var eCell = document.createElement('span');
        var number;
        if (!param.value || !isFinite(param.value)) {
            number = '';
        } else {
            number = $filter('number')(param.value, 0);
        }
        eCell.innerHTML = number;
        return eCell;
    }
}
+2
source

All Articles