a8m / angular-filter

Bunch of useful filters for AngularJS (with no external dependencies!)
https://github.com/a8m/angular-filter
MIT License
2.93k stars 332 forks source link

feat(groupby): support for property getter function (allows property transformation). #261

Closed andryfailli closed 6 years ago

andryfailli commented 6 years ago

Using a function you can group elements by a key derived from item properties. For example, you can apply a lowercase transformation to the team property.

Controller

vm.players = [
    {name: 'Gene', team: 'alpha'},
    {name: 'Andrea', team: 'Alpha'},
    {name: 'George', team: 'beta'},
    {name: 'Steve', team: 'gamma'},
    {name: 'Paula', team: 'beta'},
    {name: 'Scruath', team: 'gamma'}
];

vm.groupKeyGetterFunction = function(element) {
    return element.team.toLowerCase();
}

Temaplate

vm.players | groupBy:vm.groupKeyGetterFunction
a8m commented 6 years ago

Thanks for your contribution @andryfailli, but this capability already implemented. I created an example to demonstrate that - link.

I'm gonna close this PR, because it's irrelevant. Thanks!

andryfailli commented 6 years ago

Ouch! Ok...perfect. Maybe we can improve the documentation mentioning that a getter function can be used?

a8m commented 6 years ago

Maybe we can improve the documentation mentioning that a getter function can be used?

Sounds good. go for it 😃