2016-04-06 18 views
0

UI-grid tablo eklentisini kullanıyorum. Kullanıcı aynı kimliği girdiğinde sayı değerini güncellemek istiyorum. id aynı değilse, sayı metin kutusu değerine giren her şeyi güncelleştirmek istiyorum. sayım sadece kullanıcı aynı kimliği girerse artacaktır. itme fonksiyonu sadece kullanıcı yeni bir kimlik girerse işe yaramaz, aksi halde sadece saymayı artır. Nasıl yapabilirim? Yardımına ihtiyacım var.UI-grid kullanarak sütun değerini nasıl güncelleyebilirim

var app = angular.module('app', ['ngTouch', 'ui.grid']); 
app.controller('MainCtrl', ['$scope', 
function($scope) { 
    $scope.gridOptions = {}; 
    $scope.Delete = function(row) { 
     var index = $scope.gridOptions.data.indexOf(row.entity); 
     $scope.gridOptions.data.splice(index, 1); 
    }; 
    $scope.gridOptions.columnDefs =[{ field:"Id", displayName: "Id"},{ field:"Display", displayName: "Display"},{ field:"Count", displayName: "Count"}]; 

     $scope.addedid=0;  
     $scope.myVaridarr=[]; 
     $scope.addid = function(myVarid,countVar){ 

    $scope.addedid = +$scope.addedid+ +countVar; 

      var addToArray=true; 
    for(var i=0;i<$scope.myVaridarr.length;i++){ 
    if($scope.myVaridarr[i]===myVarid){ 
    addToArray=false; 

    alert("Id already is there"); 
    $scope.gridTwoValue = 
     { 
       "Id": myVarid, 
     "Display": "Carney", 
     "Count": $scope.addedid 
     }; 
    $scope.gridOptions.data.push ($scope.gridTwoValue); 
    } 
    } 
    if(addToArray){alert("New Id"); 
    $scope.myVaridarr.push(myVarid); 
    $scope.gridTwoValue = 
     { 
       "Id": myVarid, 
     "Display": "Carney", 
     "Count": $scope.addedid 
     }; 
    $scope.gridOptions.data.push ($scope.gridTwoValue); 
    }}; }]); 

Kod: ben bu komut dosyası eklemek istediğiniz http://jsfiddle.net/3ryLqa9e/452/

cevap

0
   $scope.gridOptions.data[index] = { 
        "Id": myVarid, 
        "Display": "Carney", 
        "Count": $scope.addedid 

       }; 
+0

Merhaba tomgal..where? –

+0

Tomgal..yazınız çalışmıyor. Yani jsfiddle'ımı düzenleyebilir misin? –

+0

http://jsfiddle.net/3ryLqa9e/455/ – tomgal

İlgili konular