ag-grid filter not working with formatted number values?
Asked Answered
C

1

6

I'm using ag grid with angularjs and the filter does not work with formatted numbers. I use formatted numbers with currency values.

Below is the columndef code:

{ headerName:"GBO", field: "GBO", width: 200, editable:true, cellClass: "number-cell",filter:'agNumberColumnFilter',
    cellRenderer : function(params){
    if(params.value == "" || params.value == null)
    return '-';
    else return params.value;
    }
}

Before assigning the data to the grid, I format the numbers using :

$scope.formatNumberOnly = function(num,c, d, t){
                //console.log(num );    
                    var n = getNumber(num);
                    //var n = this, 
                    c = isNaN(c = Math.abs(c)) ? 2 : c, 
                    d = d == undefined ? "." : d, 
                    t = t == undefined ? "," : t, 
                    s = n < 0 ? "-" : "", 
                    i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", 
                    j = (j = i.length) > 3 ? j % 3 : 0;
                   return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
                 };
        });

The problem here is that the filter doesn't work with these formatted numbers and only seems to be working for values upto 999. Can anyone please help me with a solution to this filtering problem?

Coleridge answered 17/3, 2019 at 19:27 Comment(0)
R
8

If you want the filter to work on these formatted values, you should use a valueGetter instead of a valueFormatter You should implement the above formatter function as a valueGetter in column Definition.

Also a number filter won't work as in order for your formatted number to be interpreted, it should be a text filter.

Here is an example from official docs.

Rhiannonrhianon answered 17/3, 2019 at 20:8 Comment(1)
Thanks for the information @Pratik Bhat. More specifically, wouldn't you want to use a filter value getter? ag-grid.com/javascript-data-grid/value-getters/…Bushire

© 2022 - 2024 — McMap. All rights reserved.