ng-Table Grouping: Open only row at a time

旧街凉风 提交于 2019-12-11 07:56:44

问题


I'd to display only one open row at a time in ng-Table. At present, if a row is opened then it will stay open until the user collapses it manually. As each new row is opened, there is more and more data on display.

I'm using this code to initiate the table with all rows closed, but I'm stumped at how to keep only one row closed.

app.controller('groupCtrl', function($scope) {
   $scope.group.$hideRows = true;
});

This plunkr shows the progress to date (http://plnkr.co/edit/2ABVrN?p=preview).

Ted


回答1:


The idea to pass all groups to individual group controller and collapse all expanded groups except selected

view html:

<tbody ng-repeat="group in $groups | orderBy:'value'"  sortable="'sortletter'" 
  ng-controller="groupCtrl">
  <tr class="ng-table-group">
    <td colspan="{{$columns.length}}">
      <a href="" ng-click="switchGroup(group, $parent.$groups)">

groupCtrl:

app.controller('groupCtrl', function($scope) {
  //console.log($scope); 
  $scope.group.$hideRows = true;
  //     console.log("scope.group.$hideRows"+$scope.group.$hideRows);

  $scope.switchGroup = function(group, groups){
    if(group.$hideRows){
      angular.forEach(groups, function(g){
        if(g !== group){
          g.$hideRows = true;
        }
      });
    }

    group.$hideRows = !group.$hideRows;
  };
});    

Plunker



来源:https://stackoverflow.com/questions/24841622/ng-table-grouping-open-only-row-at-a-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!