Skip to content

Commit 4a3a201

Browse files
author
Anthony HOCQUET
committed
Fix cell focus in cellNav when a new row is added
1 parent 3251d68 commit 4a3a201

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/features/cellnav/js/cellnav.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,16 +1081,23 @@
10811081
});
10821082

10831083
// This event is fired for all cells. If the cell matches, then focus is set
1084-
$scope.$on(uiGridCellNavConstants.CELL_NAV_EVENT, function (evt, rowCol, modifierDown) {
1085-
var isFocused = grid.cellNav.focusedCells.some(function(focusedRowCol, index){
1084+
$scope.$on(uiGridCellNavConstants.CELL_NAV_EVENT, refreshCellFocus);
1085+
1086+
// Refresh cell focus when a new row id added to the grid
1087+
var dataChangeDereg = uiGridCtrl.grid.registerDataChangeCallback(function (grid) {
1088+
$timeout(refreshCellFocus);
1089+
}, [uiGridConstants.dataChange.ROW]);
1090+
1091+
function refreshCellFocus() {
1092+
var isFocused = grid.cellNav.focusedCells.some(function (focusedRowCol, index) {
10861093
return (focusedRowCol.row === $scope.row && focusedRowCol.col === $scope.col);
10871094
});
1088-
if (isFocused){
1095+
if (isFocused) {
10891096
setFocused();
10901097
} else {
10911098
clearFocus();
10921099
}
1093-
});
1100+
}
10941101

10951102
function setFocused() {
10961103
if (!$scope.focused){
@@ -1113,6 +1120,8 @@
11131120
}
11141121

11151122
$scope.$on('$destroy', function () {
1123+
dataChangeDereg();
1124+
11161125
//.off withouth paramaters removes all handlers
11171126
$elm.find('div').off();
11181127
$elm.off();

0 commit comments

Comments
 (0)