Search code examples
javascriptangularjsngtable

How to hide ng-table columns?


I I've tried using ng-hide and ng-show to show one different column when vm.allRecords is set to true:

<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>

but the cells in the header are not hidden. I've also try to use custom th using this:

<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>

it work but I don't have sorting. How can I hide columns and have sorting?


Solution

  • I've changed ng-show/ng-hide to ng-if and it work.