如何使用ui-grid更新列值

时间:2016-04-06 08:35:30

标签: javascript jquery angularjs

我正在使用ui-grid table plugin.i想要在用户输入相同的id时更新计数值。如果id不相同,我想更新计数文本框值中输入的任何用户。只有当用户输入相同的ID时,count才会增加。 push函数只有在用户输入新id时才有效,否则只计数增加。 我该怎么做?。我需要任何人的帮助。

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

代码:http://jsfiddle.net/3ryLqa9e/452/

1 个答案:

答案 0 :(得分:0)

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

                };