Angular JS Magazine

vineri, 29 august 2014

Bootstrap, table striping and show/hide rows

You may find a strange behaviour when you try to display a Bootstrap table-striped as below:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="../angular/angular.min.js"></script>
    <link href="../bootstrap/css/bootstrap.css" rel="stylesheet" />
    <link href="../bootstrap/css/bootstrap-theme.css" rel="stylesheet" />
</head>
<body>
<div ng-app="" ng-init="atp=[
     { name: 'Nadal, Rafael (ESP)', rank: 1, available: true },
     { name: 'Djokovic, Novak (SRB)', rank: 2, available: true },
     { name: 'Federer, Roger (SUI)', rank: 3, available: false },
     { name: 'Wawrinka, Stan (SUI)', rank: 4, available: true },
     { name: 'Ferrer, David (ESP)', rank: 5, available: false }]">

    <div id="atpPanel" class="panel">
        <h3 class="panel-header">ATP SINGLES RANKINGS</h3>
        <table class="table table-striped">
            <thead>
            <tr>
                <th>Name</th>
                <th>Rank</th>
            </tr>
            </thead>
            <tbody>
            <tr ng-repeat="item in atp" ng-show="item.available">
                <td>{{item.name}}</td>
                <td>{{item.rank}}</td>
            </tr>
            </tbody>
        </table>
    </div>
</div>
</body>
</html>


Since ng-show and ng-hide doesn't affect the DOM, only some CSS classes, the Bootstrap gets dizzy. In order to fix this issue, you can try this:

...
<tr ng-repeat="item in atp | filter: {available: 'true'}">
   <td>{{item.name}}</td>
   <td>{{item.rank}}</td>
 </tr>
...

Niciun comentariu:

Trimiteți un comentariu