如何隐藏ng-table列?

时间:2016-12-01 14:34:55

标签: javascript angularjs ngtable

vm.allRecords设置为true时,我尝试使用ng-hide和ng-show显示一个不同的列:

<table ng-table="vm.tableParams" ng-hide="vm.noRecords || vm.DashboardService.loading">
    <tr ng-repeat="record in $data">
        <td title="'Title'" sortable="'title'" class="title">
            <a ng-href="{{vm.baseUrl}}#entity/displayEntity?entityId={{record.entityId}}" target="_blank">
                {{record.title}}
            </a>
        </td>
        <td title="'Date Created'" sortable="'createdDate'" class="date">{{record.createdDate}}</td>
        <td title="'Last Modified'" sortable="'lastModified'" class="date">{{record.lastModified}}</td>
        <td title="'Notebook Descriptor'" sortable="'notebookDescription[0]'" class="description">
            <ul>
                <li ng-repeat="description in record.notebookDescription">{{description}}</li>
            </ul>
        </td>
        <td title="'Witness'" sortable="'witnesses[0].display'" class="witness" ng-hide="vm.allRecords"> 
            <ul>
                <li ng-repeat="witness in record.witnesses">{{witness.display}}</li>
            </ul>
        </td>
        <td title="'Due Date'" sortable="'dueDate'" class="date" ng-hide="vm.allRecords">{{record.dueDate}}</td>
        <td title="'Status'" sortable="'status'" class="status" ng-show="vm.allRecords">{{record.status}}</td>
    </tr>
</table>

但标题中的单元格未隐藏。我也尝试使用这个使用自定义:

<tr>
    <th>Title</th>
    <th>Date Created</th>
    <th>Last Modified</th>
    <th>Notebook Descriptor</th>
    <th ng-hide="vm.allRecords">Witness</th>
    <th ng-hide="vm.allRecords">Due Date</th>
    <th ng-show="vm.allRecords">Status</th>
</tr>

它有效,但我没有排序。如何隐藏列并进行排序?

1 个答案:

答案 0 :(得分:5)

我已将ng-show / ng-hide更改为ng-if并且它可以正常工作。