1

I have a nested table structure where a table populates based on a ng-repeat of a Javascript object "metasetHashSplit" and this table in turn has a table that gets populated based on a property within called "ids". I have a requirement where I need to hide the main ng-repeat if all the elements in the internal table is filtered out. I am using "pipe"/"|" filter for the internal tables. I am unable to get handle on when or how to trigger the ng-show/hide based on if all the records in theinternal table is filtered out.

This is how the code is setup:

<tbody  ng-repeat="(metaset, ids) in metasetHashSplit">
<tr class = "meta">
    <td   rowspan = 100 >{{metaset}}</td>
</tr>
<tr class = "meta" style="margin:0;padding:0;"  ng-repeat="item in ids" >
    <td class = "innerTable">
        <table class="table  child table-hover table-bordered table-condensed " >
            <tr ng-repeat="buy in item.Buy  | filter:{ MBC: by_buyMBC }" >
                <td >{{buy.BuyId}}</td>
                <td >{{buy.BuyRelease}}</span></td>
                <td >{{buy.BuyComponentAffected}}</td>
                <td >{{buy.BuyStatus}}</span></td>
            </tr>
        </table>
    </td>
</tr>

Could somebody help me if they have found themselves in a position like this? Basically the tbody needs to show/hide with respect to the |filter:{MBC:by_buyMBC} results!

lostalien
  • 115
  • 1
  • 12

1 Answers1

2

Based on this question use:

<div ng-repeat="buy in filtered = (item.Buy | filter:{ MBC: by_buyMBC })">
</div>

So all you would do to show and hide based off that is use ng-if="filtered.length > 0" on the right element

Community
  • 1
  • 1
Chris
  • 26,744
  • 48
  • 193
  • 345
  • 1
    This is amazing. How did I miss this! Thank you, will try this out and see. – lostalien Nov 02 '15 at 22:03
  • 1
    I missed it too until once day I needed it - then had to Google like a bad boy :D – Chris Nov 02 '15 at 22:06
  • 1
    Looks like the scope of nested ng-repeats is likely to cause a lot of complication. For instance, the var "filtered" is not being recognised by the parent ng-repeat loop which needs to show/hide based on "filtered" – lostalien Nov 02 '15 at 22:16
  • 1
    In this case you may have to do the filtering on the controller using `$filter`, into something like `$scope.filteredBuyList` and then bind to that – Chris Nov 02 '15 at 22:17
  • 1
    Thinking about it you could TRY something cheeky and do something like `buy in item.filtered = (item.buy | ...` then see if you can bind to that – Chris Nov 02 '15 at 22:18