简体   繁体   English

如何使用ui-grid更新列值

[英]How can i update column value using ui-grid

I am using ui-grid table plugin.i want to update count value if user enter same id. 我正在使用ui-grid table plugin。如果用户输入相同的ID,我想更新计数值。 if id is not same i want to update whatever user enter in the count textbox value. 如果id不相同,我想更新在count文本框值中输入的任何用户。 count will increase only if user enter same id. 仅当用户输入相同的ID时,计数才会增加。 push function only should work if user enter new id otherwise only count increase. 推送功能仅在用户输入新ID时有效,否则仅增加计数。 how can i do it?. 我该怎么做?。 I need anyone help. 我需要任何人的帮助。

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

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

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

                };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM