复选框更改的UI-GRID列总和

时间:2017-03-25 11:23:03

标签: angularjs angular-ui-grid ui-grid

有人知道为什么当我多次点击不同的无线电值时,我的动态总值会发生巨大变化吗? 下面的代码应根据单选按钮自动选择复选框列。不知道为什么会有错误的计算。

switch($scope.ChangeAll.name) {
                case 'x':
              row.xBox = true;
                    row.yBox = false;
                    row.zBox = false;
                break;
                case 'y':
              row.xBox = false;
                    row.yBox = true;
                    row.zBox = false;
                break;
                case 'z':
              row.xBox = false;
                    row.yBox = false;
                    row.zBox = true;
                    break;
                default:
                    row.xBox = true;
                    row.yBox = false;
                    row.zBox = false;

                }

https://plnkr.co/edit/bAnz9kCuKWGIfWD4lEO2?p=preview

1 个答案:

答案 0 :(得分:1)

这个调整应该这样做。

angularjs ui-grid

AngularJS控制器(相关代码更改):

$scope.updateSelection = function(value) {
  switch ($scope.ChangeAll.name) {
    case 'x':
      angular.forEach($scope.myData, function(row, idx) {
        row.xBox = true;
        row.yBox = false;
        row.zBox = false;
      });
      break;
    case 'y':
      angular.forEach($scope.myData, function(row, idx) {
        row.xBox = false;
        row.yBox = true;
        row.zBox = false;
      });
      break;
    case 'z':
      angular.forEach($scope.myData, function(row, idx) {
        row.xBox = false;
        row.yBox = false;
        row.zBox = true;
      });
      break;
    default:
      angular.forEach($scope.myData, function(row, idx) {
        row.xBox = true;
        row.yBox = false;
        row.zBox = false;
      });
  }
};

所有重要的Plunker更新https://plnkr.co/edit/QOkoG9pC7gETvZ4I7Xkq?p=preview