Insert dynamic filter into an angle expression

3

I'm trying to insert a dynamic filter according to a field of an object in ng-grid . I tried in various ways and I could not:

$scope.gridOptions.columnDefs = [
    { displayName: 'entity.tipoPessoa', field: 'tipoPessoa'},
    { displayName: 'entity.id', field: 'id', cellTemplate: '<div class=\"ngCellText\" ng-class=\"col.colIndex()\"><span ng-cell-text>[Insira o trecho de código aqui]</span></div>'},
    //...
]:

Code snippet:

{{ row.entity.tipoPessoa == "F" ? row.entity.id | brCpf : row.entity.id | brCnpj }}

{{ row.entity.tipoPessoa == "F" ? "row.entity.id | brCpf" : "row.entity.id | brCnpj" }}

{{ row.entity.tipoPessoa == "F" ? "{{row.entity.id | brCpf}}" : "{{row.entity.id | brCnpj}}" }}

{{ row.entity.tipoPessoa == "F" ? {{row.entity.id | brCpf}} : {{row.entity.id | brCnpj}} }}

None of these worked. What is the right way to do it? Should I try another approach?

    
asked by anonymous 05.05.2015 / 15:53

1 answer

2

I decided to create a custom filter , of course there must be another way to do it, but I leave here the solution used:

app.filter('CpfCnpj', ['$filter', function($filter) {
    return function(CpfCnpj) {
        var cpfSize = 11;
        return CpfCnpj.length <= cpfSize ? $filter('brCpf')(CpfCnpj) : $filter('brCnpj')(CpfCnpj);
    };
}]);
    
05.05.2015 / 16:53