UI-GRID column summation on checkbox change

℡╲_俬逩灬. 提交于 2019-12-23 22:33:34

问题


Does anyone know why when I click on different radio values multiple times, my Dynamic Total value changes drastically? The code below should automatically select the column of checkboxes according to the radio buttons. Not sure why there would be miscalculations.

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:


This tweak should do it.

AngularJS Controller (relevant code change):

$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;
      });
  }
};

And the all important Plunker update, https://plnkr.co/edit/QOkoG9pC7gETvZ4I7Xkq?p=preview.



来源:https://stackoverflow.com/questions/43015734/ui-grid-column-summation-on-checkbox-change

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