Cela devrait le faire:
Code pertinent du contrôleur:
var used = [];
$scope.grandTotal = 0;
angular.forEach($scope.myData,function(row,idx){
row.getTotal = function(){
if (used.indexOf(idx) == -1) {
$scope.grandTotal += this.x + this.y;
used.push(idx);
}
return this.x + this.y ;
};
});
Votre Plunker mise à jour est ici, http://plnkr.co/edit/1FHgSViYgpfXgQEPfXr5?p=preview.
mise à jour (en fonction de la réponse/plunker-link/commentaire ci-dessous)
Nouvelle mise en page de l'écran:
Code pertinent du contrôleur:
var used = [];
$scope.grandTotal = 0;
angular.forEach($scope.myData, function(row, idx) {
row.getTotal = function() {
var value;
if (this.xBox) {
value = this.x + this.z;
} else if (this.yBox) {
value = this.y + this.z;
}
if (used.indexOf(idx) == -1) {
$scope.grandTotal += value;
used.push(idx);
}
return value;
};
});
$scope.updateXRowClear = function(row) {
row.entity.yBox = false;
/* Need to check the ybox cell when unchecked */
if (row.entity.xBox === false) {
row.entity.yBox = true;
$scope.grandTotal += row.entity.y - row.entity.x;
} else {
$scope.grandTotal += row.entity.x - row.entity.y;
}
};
$scope.updateYRowClear = function(row) {
row.entity.xBox = false;
/* Need to check the xbox cell when unchecked */
if (row.entity.yBox === false) {
row.entity.xBox = true;
$scope.grandTotal += row.entity.x - row.entity.y;
} else {
$scope.grandTotal += row.entity.y - row.entity.x;
}
};
Nouvelle mise à jour Plunker, https://plnkr.co/edit/ixdN0J2oVvOlbbziJMCY?p=preview.
Mis à jour Encore une fois (en fonction des commentaires ci-dessous)
Nouvelle mise en page de l'écran:
Code pertinent du contrôleur:
var used = [];
$scope.grandTotal = 0;
angular.forEach($scope.myData, function(row, idx) {
row.getTotal = function() {
var value;
if (this.xBox) {
value = this.x * this.qty;
} else if (this.yBox) {
value = this.y * this.qty;
} else if (this.zBox) {
value = this.z * this.qty;
}
if (used.indexOf(idx) == -1) {
$scope.grandTotal += value;
used.push(idx);
}
return value;
};
$scope.$watch(
function($scope) {
return row.getTotal();
},
function(newValue, oldValue) {
$scope.grandTotal += (newValue ? newValue : 0) - (oldValue ? oldValue : 0);
}
);
});
$scope.updateXRowClear = function(row) {
row.entity.yBox = false;
row.entity.zBox = false;
/* Need to check the ybox cell when unchecked */
if (row.entity.xBox === false) {
row.entity.yBox = true;
}
if (row.entity.yBox === false) {
row.entity.xBox = true;
}
};
$scope.updateYRowClear = function(row) {
row.entity.xBox = false;
row.entity.zBox = false;
/* Need to check the xbox cell when unchecked */
if (row.entity.yBox === false) {
row.entity.xBox = true;
} else if (row.entity.xBox === false) {
row.entity.yBox = true;
}
};
$scope.updateZRowClear = function(row) {
row.entity.xBox = false;
row.entity.yBox = false;
/* Need to check the zbox cell when unchecked */
if (row.entity.zBox === false) {
row.entity.xBox = true;
} else if (row.entity.xBox === false) {
row.entity.zBox = true;
} else if (row.entity.yBox === false) {
row.entity.yBox = true;
}
};
Et le tout Plunker travail importante, https://plnkr.co/edit/1rRRWEIyQhKVkYRdtIFu?p=preview. Faites-moi savoir si vous avez d'autres questions, heureux de vous aider!
Merci Tim! Maintenant, comment le rendre dynamique? https://plnkr.co/edit/vhstPeg2BYz1oWGGwido?p=preview – UCDaCode
Je remarque que lorsque je clique sur la même case à cocher plus d'une fois, le grand-nombre incrémente. – UCDaCode
Wow! Tu es rapide! Ok, deux autres choses: 1. Je veux maintenant ajouter une autre colonne. Lorsque je passe de la colonne y à z et inversement, le total dynamique est incorrect. 2. Comment est-ce que je mettrais à jour le total dynamique quand j'éditerais la colonne de quantité? PS Vous êtes aidé est profondément apprécié. =) – UCDaCode