2017-02-27 64 views

回答

1

我相信這可能接近您想要的,Mero。

enter image description here

的JavaScript/AngularJS控制器:

var app = angular.module('app', ['ui.grid', 'ui.grid.selection']); 
app.controller('MainCtrl', ['$scope', '$http', function($scope, $http) { 
    $scope.mySelections = []; 
    $scope.mySelectionsInOrder = []; 
    $scope.gridOnRegisterApi = function(gridApi) { 
    gridApi.selection.on.rowSelectionChanged($scope, function(row) { 
     $scope.mySelections = gridApi.selection.getSelectedRows(); 
     if (row.isSelected) { 
     $scope.mySelectionsInOrder.push(row.entity); 
     } else { 
     $scope.mySelectionsInOrder.splice($scope.mySelectionsInOrder.indexOf(row.entity), 1); 
     } 
     console.log($scope.mySelections); 
    }); 
    }; 
    $scope.gridOptions = { 
    enableSelectAll: true, 
    enableRowSelection: true, 
    enableRowHeaderSelection: false, 
    enableFullRowSelection: true, 
    showGridFooter: true, 
    onRegisterApi: $scope.gridOnRegisterApi 
    } 
    $http.get('data.json') 
    .then(function(response) { 
     $scope.gridOptions.data = response.data; 
    }); 
}]); 

的基本思路是,以保持rowSelectionChanged活動期間跟蹤選項,並與row.isSelected確定是否我們應該pushsplice

這是一個可以工作的Plunker,http://plnkr.co/edit/lnng9coOQHca3PzOSjQI?p=preview

希望這可以幫助,讓我知道如果你有任何問題。