Hiding table body when all the rows are hidden in angularjs -


i'm trying display table activities, row displaying day , after list of activities day. want user able filter activities. "myactivities" map user's activities assigned true, , rest false. code looks this:

<table> <tbody ng-repeat="date in dates"> <tr><td>{{date.day}}</td></tr> <tr ng-repeat="activity in date.activities" ng-show="myactivities[activity.id] == true">     <td>{{activity.time}}</td><td>{{activity.name}}</td> </tr> </tbody> </table> 

the problem when there day no relevant activities user, row displaying date still shown activities under hidden. solved problem function:

$scope.checkdate = function(activities) {     activities.foreach(function(activity){         if (myactivities[activity.id] == true) return true;     });     return false; }  //added ng-show tbody in html: <tbody ng-repeat="date in dates" ng-show="checkdate(date.activities)"> 

it works perfectly, best solution? have feeling there nicer solution. ideas ?

thanks!

you can assign filtered variables date object, , check length of property:

<table>     <tbody ng-repeat="date in dates"             ng-show="date.filteredactivities.length">         <tr>             <td>{{ date.day }}</td>         </tr>         <tr ng-repeat="activity in (date.filteredactivities = (date.activities | filter: { active: true }))">             <td>{{ activity.time }}</td>             <td>{{ activity.name }}</td>         </tr>     </tbody> </table> 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -