How to get the cell value from ng-grid

前端 未结 3 2021
被撕碎了的回忆
被撕碎了的回忆 2021-01-06 03:06

I am a beginner of AngularJS. I study the demo of ng-grid and have a question.

index.html






        
相关标签:
3条回答
  • 2021-01-06 03:38

    You can access the rowItem of the selected row with the arguments to the afterSelectionChange event. The entity property will have the id and name properties.

     $scope.gridOptions = { 
        data: 'myData',
        selectedItems: $scope.mySelections,
        multiSelect: true,
        afterSelectionChange: function (theRow, evt) {      
           alert(theRow.entity.id);
    }
    

    };

    0 讨论(0)
  • 2021-01-06 03:53

    Use the afterSelectionChange callback to extract the ids from the selection to an other array.

    $scope.gridOptions = { 
        data: 'myData',
        selectedItems: $scope.mySelections,
        multiSelect: true,
        afterSelectionChange: function () {
          $scope.selectedIDs = [];
          angular.forEach($scope.mySelections, function ( item ) {
            $scope.selectedIDs.push( item.id )
          });
        }
      };
    

    now you can reference {{selectedIDs}} from the template and has all the selected ids in it. Or just the first: {{selectedIDs[0]}}

    See the working example here: http://plnkr.co/edit/xVwVWX

    0 讨论(0)
  • 2021-01-06 03:57

    Acutally, I want to get a cell value and modify when user selects the cell at the table.

    Above answers are using fixed columns's filed.. like

     $scope.selectedIDs.push( item.id ) // id is column filed
    

    Instead of these answers, I found another way exactly what I want to achieve with.

    Example code: http://plnkr.co/edit/wfiMhlJ7by4eUHojjKT4?p=preview

    editableCellTemplate which is an option for columnDefs is used for solving this problem.

    Angular is Aswome!!

    0 讨论(0)
提交回复
热议问题