Bạn có thể nhận các mảng của các hàng, trong tình trạng sắp xếp và lọc của họ, từ $scope.gridApi.grid.renderContainers.body.visibleRowCache
. Ngoài ra còn có một loạt các trickiness để đối phó với khi bạn có thực thể và khi bạn có gridRow, do đó, mã được một chút phức tạp.
Mã của bạn sẽ là một cái gì đó như:
$scope.selectNextRow = function() {
var currentRowIndex;
var selectedRows = $scope.gridApi.selection.getSelectedRows();
if(selectedRows.length < 1){
// if nothing selected, we'll select the top row
currentRowIndex = -1;
} else {
// if there are multiple selected, we use the first one
var selectedRow = selectedRows[0];
var gridRow = $scope.gridApi.grid.getRow(selectedRow);
currentRowIndex = $scope.gridApi.grid.renderContainers.body.visibleRowCache.indexOf(gridRow);
}
$scope.gridApi.selection.clearSelectedRows();
$scope.gridApi.selection.selectRow($scope.gridApi.grid.renderContainers.body.visibleRowCache[currentRowIndex + 1].entity);
};
Tham khảo http://plnkr.co/edit/Z7HCjVY6oxGJzyjLI6Qo?p=preview
IMHO, tôi sẽ đính kèm một id để mỗi hàng và chọn bởi id hàng. – ABOS