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

How to use GroupBy with Max ? #219

Closed yellooo closed 8 years ago

yellooo commented 8 years ago

I have an object like this:

[{code: 'AZ33', label: 'foo', score: 0.1224},
{code: 'AZ33', label: 'foo', score: 0.5234},
 {code: 'B44', label: 'foo', score: 0.5234},
{code: 'B44', label: 'foo', score: 0.6000}]

I made groupBy on the 'code', so i get this output:

AZ33
B44

but i want to filter it on the max 'score' value too.

AZ33, 0.5234
B44, 0.6000

How can i do that with GroupBy and Max, i already try something:

<tr ng-repeat="group in groups | toArray:true">
    <td ng-bind="group.$key"></td>  
    <td ng-repeat="data in group | max: 'data.score'">
        <span ng-bind="data.score ? (data.score*100 | number:0) + '%' : '-'"></span>
    </td>
</tr>
yellooo commented 8 years ago

Oki i resovle it ;)