How can one apply conditional grouping in an Angular
For example, in the below code, I want to
groupBy:'var1', but only when some variable, or expression,
dontGroup evaluates to true. I don't want to have the bottom
tr row duplicated specifically for the
dontGroup variable in my HTML because the information cannot be loaded in via a template for a second
tr due to the main table being controlled by a directive and needing the template in the DOM before initialization. If there's a way to do this that I'm overlooking, please let me know. I'm utilizing
<table> <tr ng-repeat-start="(key, data) in $data | groupBy:'var1'"> <td ng-bind="key"> <!-- Grouped header info here. --> </td> </tr> <tr ng-repeat-end ng-repeat="item in data"> <!-- Repeat $data when `dontGroup` evaluates to true, otherwise repeat pre-grouped data from the `groupBy` filter above --> <td ng-bind="item.var2"> <!-- Individual item info here. --> </td> </tr> </table>
So, I want the lower
ng-repeat function to repeat
data only when
dontGroup evaluates to true, but otherwise I want
$data to be run through the
groupBy filter such that the data can have a header for the group.
I also cannot just drop an
ng-if on the header row when
dontGroup evaluates to true because I need the data to sort by other variables such as
var3, etc, and not have the
var1 grouping affect that.
A fiddle for you to play with showing both wanted functionalities.