UI-Grid - 如何使用select所有复选框在当前页面显示select条记录
UI-Grid - How to select records displayed in the current page using selectAll checkbox
在UI-grid "select All"复选框中,选中后,select显示当前页面以及其他页面可见的所有记录。
问题 - 怎样才能select行只显示在当前页面。
笨蛋
http://plnkr.co/edit/gHiER0A2Oaia4HMWChcG?p=preview
尝试了 api $scope.gridApi.selection.selectAllVisibleRows();
但它没有 select 仅显示在当前页面中的行。如果您单击 "Select Visible Rows" 按钮并移至下一页,则那里的记录也会 selected.
其他详情apiselectAllVisibleRows
在 ui-grid 函数中检查时 selectAllVisibleRows。 row.visible
returns true
为 all the rows across all pages
。
selectAllVisibleRows: function (evt) {
if (grid.options.multiSelect === false) {
return;
}
var changedRows = [];
grid.rows.forEach(function (row) {
if (row.visible) {
if (!row.isSelected && row.enableSelection !== false){
row.setSelected(true);
service.decideRaiseSelectionEvent( grid, row, changedRows, evt );
}
} else {
if (row.isSelected){
row.setSelected(false);
service.decideRaiseSelectionEvent( grid, row, changedRows, evt );
}
}});
service.decideRaiseSelectionBatchEvent( grid, changedRows, evt );
grid.selection.selectAll = true;
},
尝试使用 for 循环 这里是 plunker link!
为了 select 当前网格页面中的行,您必须在注册其 API 时为 ui-grid v4.4.9 rowSelectionChangedBatch 事件添加一个处理程序。方法。正如您所指出的,它认为所有未过滤的行都是可见的。它不排除未在当前网格页面上呈现的行。因此,我们不得不自己动手:
onRegisterApi: function (gridApi) {
gridApi.selection.on.rowSelectionChangedBatch(null, function (rows) {
var grid = this.grid;
// you'll need ui-grid v4.4.9 or better
// otherwise you'll need to invert getSelectAllState()
// as explained at https://github.com/angular-ui/ui-grid/issues/5411
var isAllSelected = grid.api.selection.getSelectAllState();
// when select all is checked, the default behavior is to select all grid rows on all pages
// so we have to deselect them all first before we select just the ones on the visible page
grid.api.selection.clearSelectedRows(null);
if (isAllSelected) {
// select only the rows displayed in the current grid page
var startIndex = (grid.options.paginationCurrentPage - 1) * grid.options.paginationPageSize;
var endIndex = startIndex + grid.options.paginationPageSize;
for (let i = startIndex; i < endIndex; i++) {
let row = grid.rows[i];
row.isSelected = true;
}
}
});
},
onRegisterApi: function(gridApi) {
gridApi.selection.on.rowSelectionChangedBatch($scope, function() {
// check for ui-grid version to revert opposite value
var isAllSelected = gridApi.selection.getSelectAllState();
if (isAllSelected) {
// unselect all rows as select all button selects all rows by default
gridApi.selection.clearSelectedRows();
/* Will fetch only grid rows visible on page. It will fetch the correct
rows even if you have applied sorting, pagination and filters. */
var gridRows = this.grid.getVisibleRows();
// function to set Selected to only visible rows
angular.forEach(gridRows, function(gridRow) {
gridRow.setSelected(true);
});
}
$scope.selectedRows = gridApi.selection.getSelectedRows();
});
}
在UI-grid "select All"复选框中,选中后,select显示当前页面以及其他页面可见的所有记录。
问题 - 怎样才能select行只显示在当前页面。
笨蛋 http://plnkr.co/edit/gHiER0A2Oaia4HMWChcG?p=preview
尝试了 api $scope.gridApi.selection.selectAllVisibleRows();
但它没有 select 仅显示在当前页面中的行。如果您单击 "Select Visible Rows" 按钮并移至下一页,则那里的记录也会 selected.
其他详情apiselectAllVisibleRows
在 ui-grid 函数中检查时 selectAllVisibleRows。 row.visible
returns true
为 all the rows across all pages
。
selectAllVisibleRows: function (evt) {
if (grid.options.multiSelect === false) {
return;
}
var changedRows = [];
grid.rows.forEach(function (row) {
if (row.visible) {
if (!row.isSelected && row.enableSelection !== false){
row.setSelected(true);
service.decideRaiseSelectionEvent( grid, row, changedRows, evt );
}
} else {
if (row.isSelected){
row.setSelected(false);
service.decideRaiseSelectionEvent( grid, row, changedRows, evt );
}
}});
service.decideRaiseSelectionBatchEvent( grid, changedRows, evt );
grid.selection.selectAll = true;
},
尝试使用 for 循环 这里是 plunker link!
为了 select 当前网格页面中的行,您必须在注册其 API 时为 ui-grid v4.4.9 rowSelectionChangedBatch 事件添加一个处理程序。方法。正如您所指出的,它认为所有未过滤的行都是可见的。它不排除未在当前网格页面上呈现的行。因此,我们不得不自己动手:
onRegisterApi: function (gridApi) {
gridApi.selection.on.rowSelectionChangedBatch(null, function (rows) {
var grid = this.grid;
// you'll need ui-grid v4.4.9 or better
// otherwise you'll need to invert getSelectAllState()
// as explained at https://github.com/angular-ui/ui-grid/issues/5411
var isAllSelected = grid.api.selection.getSelectAllState();
// when select all is checked, the default behavior is to select all grid rows on all pages
// so we have to deselect them all first before we select just the ones on the visible page
grid.api.selection.clearSelectedRows(null);
if (isAllSelected) {
// select only the rows displayed in the current grid page
var startIndex = (grid.options.paginationCurrentPage - 1) * grid.options.paginationPageSize;
var endIndex = startIndex + grid.options.paginationPageSize;
for (let i = startIndex; i < endIndex; i++) {
let row = grid.rows[i];
row.isSelected = true;
}
}
});
},
onRegisterApi: function(gridApi) {
gridApi.selection.on.rowSelectionChangedBatch($scope, function() {
// check for ui-grid version to revert opposite value
var isAllSelected = gridApi.selection.getSelectAllState();
if (isAllSelected) {
// unselect all rows as select all button selects all rows by default
gridApi.selection.clearSelectedRows();
/* Will fetch only grid rows visible on page. It will fetch the correct
rows even if you have applied sorting, pagination and filters. */
var gridRows = this.grid.getVisibleRows();
// function to set Selected to only visible rows
angular.forEach(gridRows, function(gridRow) {
gridRow.setSelected(true);
});
}
$scope.selectedRows = gridApi.selection.getSelectedRows();
});
}