感謝您的回答,這是非常有用的。移動選擇到下一行刪除後,你可以做這樣的(單選擇)
//步驟01:記住當前選擇的rowIndex:
gridOptions.afterSelectionChange: function(row, event) {
$scope.gridOptions.rowIndex = row.rowIndex;}
//步驟02:刪除行和招選擇
$scope.deleteRecord = function() {
var arrayIndex = $scope.gridOptions.ngGrid.rowMap.indexOf(rowItem.rowIndex);
var rowIndex = $scope.gridOptions.rowIndex; `on sorted grids these to might differ`
var e = $scope.$on('ngGridEventData', function() {
if (rowIndex >= $scope.gridItems.length) {
// last element is deleted, thus move selection up
rowIndex--;
}
if (rowIndex >= 0) {
$scope.gridOptions.selectRow(rowIndex, true);
$scope.focusRow(rowIndex);
e(); // deregister the listener
$scope.entity2View();
}
});
$scope.gridItems.splice(arrayIndex, 1);});