我相信這可能接近您想要的,Mero。
的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
確定是否我們應該push
或splice
。
這是一個可以工作的Plunker,http://plnkr.co/edit/lnng9coOQHca3PzOSjQI?p=preview。
希望這可以幫助,讓我知道如果你有任何問題。