-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add choices grouping using 'group by' expression #49
Conversation
Please merge this feature. |
1 similar comment
Please merge this feature. |
@tkrotoff please merge this feature, it's very helpful |
+1 |
2 similar comments
👍 |
👍 |
The only issue I have with this is that the value of Other than that it looks great, +1 from me |
Just have rebased code from the current master. I have to implicitly declare angular version, because later versions are incompatible and fail the tests |
@just-boris thanks for pointing out that declaring angular version fixes the failing tests. That actually makes sense since after 1.2.18 we have some changes on how angular manages ngTransclude and that affects the directive. PR #91 is already in progress to fix 1.2.18+ |
@just-boris I created and merged #95 to fix this asap |
rebased again. |
👍 |
@dimirc @tkrotoff please feel free to do what you guys think is best as I'm no longer actively working on these projects. My one concern I will have is feature and code bloat. If there is absolutely no other way to achieve this other than creating an explicit syntax for it then so be it. But I wonder about alternative edge-cases (such as nested arrays for grouping instead of grouping by a property). I'd much rather provide users with a strong api like an iterator callback or something to allow users to do this themselves. For instance, if the dev turns this into a nested array or object, couldn't he just do a double ng-repeat inside his custom template or something? Anyway, you guys should do what you wish, and if you find some people are very active on the project feel free to add them to the org. |
A little detail about this implementation is, if there's no group (even if On Tue, Jul 1, 2014 at 6:52 PM, Dean Sofer [email protected] wrote:
|
Instead of the explicit syntax, I think that we could better have an attribute and pass a string (the property that we want to use for grouping) or function for a more complex operation. Similar to _.groupBy <choices group-by="'age'" repeat="item in people | filter: $select.search">
<span ng-bind-html="item.name | highlight: $select.search"></span>
<small ng-bind-html="item.email | highlight: $select.search"></small>
</choices> or <choices group-by="someFunction" repeat="item in people | filter: $select.search">
<span ng-bind-html="item.name | highlight: $select.search"></span>
<small ng-bind-html="item.email | highlight: $select.search"></small>
</choices> |
@dimirc ok, it will be easier to realize than have an additional token in repeat attribute, so I agree with you. |
Yes, will be perfect if you could do the changes and we'll merge this feature asap Sent from my iPhone
|
@dimirc, done |
ctrl.groups[groupValue].push(item); | ||
} | ||
}); | ||
angular.forEach(ctrl.groups, function(group, key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of clearing the arrays for each group and then deleting empty one, why not just always starting with a new empty object for ctrl.groups?
Like this
function updateGroups(items) {
ctrl.groups = {};
angular.forEach(items, function(item) {
var groupFn = $scope.$eval(groupByExp);
var groupValue = angular.isFunction(groupFn) ? groupFn(item) : item[groupFn];
if(!ctrl.groups[groupValue]) {
ctrl.groups[groupValue] = [item];
}
else {
ctrl.groups[groupValue].push(item);
}
});
setPlainItems(items);
}
I can reproduce a bug with key navigation in just one case: when grouped by value with both lower and uppercase letters: http://plnkr.co/edit/pvO8aL?p=preview |
Add choices grouping using 'group by' expression
@just-boris some additional changes will be merged at #102, thanks for your PR and any additional help to improve the library are welcome |
@just-boris if you have some free time, will be nice to have some help on PR #138, specially on the task "Check choices with groupby to work correctly on "multiple" mode" |
As described in #48, I've done options grouping.
Here is plunker where you can see this changes in action.