samstokes / ng-group

Angular.js filter for grouping items by a field.
MIT License
18 stars 8 forks source link

Adding ability to group by angular expressions #2

Open cjwainwright opened 9 years ago

cjwainwright commented 9 years ago

I think it would be useful to be able to group on nested fields, as can be done with orderBy, such as

<div ng-repeat="placePeople in people | groupBy:'homeAddress.town':'peopleByHome'">
<h2>{{placePeople['homeAddress.town']}}</h2>

These changes make use of $parse to achieve this.

Note it is a backwards incompatible change in terms of grouping by functions, as now you can't leave off the braces in the expression, i.e.

<div ng-repeat="placePeople in people | groupBy:'uptown()':'peopleByHome'">
<h2>{{placePeople['uptown()']}}</h2>

So probably would need a version bump.

Given these changes, I'd be tempted to make a further change (which is not included here) to use a fixed name for the group key, rather than the expression, as the above would probably look neater with

<h2>{{placePeople.groupKey}}</h2>

Hope this is useful. Let me know any thoughts, thanks.