2

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

UCDaCode
  • 65
  • 7

1 Answers1

1

This tweak should do it.

angularjs ui-grid

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.

Tim Harker
  • 2,367
  • 1
  • 15
  • 28