How to get the cell value from ng-grid

前端 未结 3 2047
被撕碎了的回忆
被撕碎了的回忆 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: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

提交回复
热议问题