如何从网格中过滤这些行时取消选择行? 在angular-ui-grid中有没有可以完成这项工作的旗帜?类似的东西:
function A = pushmatrixup(A)
% Loop over each column of matrix A
for col = 1:size(A,2)
% Rearrange the values in column 'col', with the logic:
% [Values in column 'col' which don't equal 0;
% Values in column 'col' which do equal 0]
A(:,col) = [A(A(:,col) ~= 0, col); A(A(:,col) == 0, col)];
end
% All columns now have their 0s 'sunk' to the bottom of the column.
end
答案 0 :(得分:1)
如果只有gridOptions.removeSelectedAfterFilterd = true
。
这是一个有效的替代方案:
var app = angular.module('app', ['ui.grid', 'ui.grid.selection']);
app.controller('MainCtrl', ['$scope', '$timeout',
function($scope, $timeout) {
$scope.gridOptions = {
enableFiltering: true,
enableSelectAll: true,
enableRowSelection: true,
enableRowHeaderSelection: false,
enableFullRowSelection: true,
showGridFooter: true,
onRegisterApi: function(gridApi) {
$scope.gridApi = gridApi;
$scope.gridApi.core.on.filterChanged($scope, function() {
$timeout(function() {
angular.forEach($scope.gridApi.selection.getSelectedGridRows(), function(row) {
if (!row.visible) $scope.gridApi.selection.unSelectRow(row.entity);
});
}, 10);
});
},
columnDefs: [{name: 'FirstName'}, {name: 'LastName'}, {name: 'Job'}],
data: [{"FirstName": "nir", "LastName": "OP", "Job": "Stack Overflow User"},
{"FirstName": "Tim", "LastName": "Harker", "Job": "Stack Overflow User"},
{"FirstName": "nir", "LastName": "OP", "Job": "Stack Overflow User"}]
};
}
]);

div[ui-grid] {
height: 190px;
}

<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-grid/4.0.2/ui-grid.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/angular-ui-grid/4.0.2/ui-grid.min.css" />
<div ng-app="app" ng-controller="MainCtrl">
<div ui-grid="gridOptions" ui-grid-selection class="grid"></div>
</div>
&#13;
如果您有任何其他问题,请告诉我,我们乐意为您提供帮助。
答案 1 :(得分:1)
就像Tim Harker的回答一样,无需添加“$ timeout”
var app = angular.module('app', ['ui.grid', 'ui.grid.selection']);
app.controller('MainCtrl', ['$scope', '$timeout',
function($scope, $timeout) {
$scope.gridOptions = {
enableFiltering: true,
enableSelectAll: true,
enableRowSelection: true,
enableRowHeaderSelection: false,
enableFullRowSelection: true,
showGridFooter: true,
onRegisterApi: function(gridApi) {
$scope.gridApi = gridApi;
$scope.gridApi.core.on.rowsVisibleChanged($scope, function() {
angular.forEach($scope.gridApi.selection.getSelectedGridRows(), function(row) {
if (!row.visible) {
$scope.gridApi.selection.unSelectRow(row.entity)
};
});
});
},
columnDefs: [{name: 'FirstName'}, {name: 'LastName'}, {name: 'Job'}],
data: [{"FirstName": "nir", "LastName": "OP", "Job": "Stack Overflow User"},
{"FirstName": "Tim", "LastName": "Harker", "Job": "Stack Overflow User"},
{"FirstName": "nir", "LastName": "OP", "Job": "Stack Overflow User"}]
};
}
]);
div[ui-grid] {
height: 190px;
}
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-grid/4.0.2/ui-grid.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/angular-ui-grid/4.0.2/ui-grid.min.css" />
<div ng-app="app" ng-controller="MainCtrl">
<div ui-grid="gridOptions" ui-grid-selection class="grid"></div>
</div>