简体   繁体   中英

Changing ng-grid cell value using a HTML button?

I want my code to update the cell of ng-grid based on which row's update button has been clicked. I want values to be updated after I press the update button defined in HTML code and not the one in ng-grid . How should I call and define update1(); function in my code ?

Here's the plunker: http://plnkr.co/edit/Cdnc1HQKAbCvZ0bW2Uei?p=preview

My JS update1 function:

$scope.update1 = function(){
    $scope.Name = $scope.student.name;
    row.entity.Age = $scope.student.class;
};

My HTML button code:

<button ng-click="update1()">Update</button>

Store the row value which you are passing to update function. When you click on the update function of the grid make sure you save row value.

$scope.update = function(row) {
    var name = row.entity.Name;
    var age = row.entity.Age;

    **$scope.student.row = row;**
    $scope.student.name = name;
    $scope.student.class = age;
  };

Now in your HTML update1 function you can just assign the entered values to the respective row data.

$scope.update1 = function() {
    // alert($scope.student.row);
    if($scope.student.row !== undefined) {
      $scope.student.row.entity.Name =  $scope.student.name;
      $scope.student.row.entity.Age =  $scope.student.class;

      $scope.student.name = " ";
      $scope.student.class = " ";
      $scope.student.row = undefined;  
    }
  };

PS: I want to show the results on plunker. But it seems to be down at the moment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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