如何在ng-grid中获取选定的行ID(AngularJS)

时间:2015-02-23 13:49:10

标签: angularjs

我希望删除所选行。所以我想要选择ids

 $scope.gridOptions = {
    data: 'myData',
    enablePaging: true,
    showSelectionCheckbox :true,
    resizable :true,
    showFooter: true,
    multiSelect: true,
    selectedItems:$scope.mySelections,
    totalServerItems:'totalServerItems',
    pagingOptions: $scope.pagingOptions,
    filterOptions: $scope.filterOptions,
    afterSelectionChange: function () {
      $scope.selectedIDs = []; 
      angular.forEach($scope.mySelections, function ( item ) {
          $scope.selectedIDs.push(item.ID);
      });
    },
columnDefs: [
               { field: 'iSchl_Id', displayName: 'ID' },
               { field: 'vSchl_Name', displayName: 'School Name' },
               { field: 'vCity', displayName: 'City' },
               { field: 'vState', displayName: 'State' },
               { field: 'vCountry', displayName: 'Country' },
               { field: 'vEmail', displayName: 'Email' },
               { field: 'iStatus', displayName: 'Status' },
       { field: '', cellTemplate: '<button ng-click="edit(row.entity)" title="Edit" class="icon-edit edt-btn"></button><button ng-click="delete(row.entity)" title="Delete" class="icon-trash dlt-btn"></button>',displayName: 'Action'}
    ],
};

我在网格中使用了动态数据。我尝试了How to get the cell value from ng-grid示例但我没有得到selectedIDs.I得到错误:项目未定义

Deleteall功能:

$scope.deleteall = function() {
     var verify=confirm('Are you sure to want this delete all selected record?');
      if(verify==true)
      {
           //Please give me logic of selected ids
      }
    };

0 个答案:

没有答案