|
1069 | 1069 | });
|
1070 | 1070 | }
|
1071 | 1071 |
|
| 1072 | + // In case we created a new row, and we are the new created row by ngRepeat |
| 1073 | + // then this cell content might have been selected previously |
| 1074 | + refreshCellFocus(); |
| 1075 | + |
1072 | 1076 | function preventMouseDown(evt) {
|
1073 | 1077 | //Prevents the foucus event from firing if the click event is already going to fire.
|
1074 | 1078 | //If both events fire it will cause bouncing behavior.
|
|
1083 | 1087 | });
|
1084 | 1088 |
|
1085 | 1089 | // This event is fired for all cells. If the cell matches, then focus is set
|
1086 |
| - $scope.$on(uiGridCellNavConstants.CELL_NAV_EVENT, function (evt, rowCol, modifierDown) { |
1087 |
| - var isFocused = grid.cellNav.focusedCells.some(function(focusedRowCol, index){ |
| 1090 | + $scope.$on(uiGridCellNavConstants.CELL_NAV_EVENT, refreshCellFocus); |
| 1091 | + |
| 1092 | + // Refresh cell focus when a new row id added to the grid |
| 1093 | + var dataChangeDereg = uiGridCtrl.grid.registerDataChangeCallback(function (grid) { |
| 1094 | + // Clear the focus if it's set to avoid the wrong cell getting focused during |
| 1095 | + // a short period of time (from now until $timeout function executed) |
| 1096 | + clearFocus(); |
| 1097 | + |
| 1098 | + $timeout(refreshCellFocus); |
| 1099 | + }, [uiGridConstants.dataChange.ROW]); |
| 1100 | + |
| 1101 | + function refreshCellFocus() { |
| 1102 | + var isFocused = grid.cellNav.focusedCells.some(function (focusedRowCol, index) { |
1088 | 1103 | return (focusedRowCol.row === $scope.row && focusedRowCol.col === $scope.col);
|
1089 | 1104 | });
|
1090 |
| - if (isFocused){ |
| 1105 | + if (isFocused) { |
1091 | 1106 | setFocused();
|
1092 | 1107 | } else {
|
1093 | 1108 | clearFocus();
|
1094 | 1109 | }
|
1095 |
| - }); |
| 1110 | + } |
1096 | 1111 |
|
1097 | 1112 | function setFocused() {
|
1098 | 1113 | if (!$scope.focused){
|
|
1115 | 1130 | }
|
1116 | 1131 |
|
1117 | 1132 | $scope.$on('$destroy', function () {
|
| 1133 | + dataChangeDereg(); |
| 1134 | + |
1118 | 1135 | //.off withouth paramaters removes all handlers
|
1119 | 1136 | $elm.find('div').off();
|
1120 | 1137 | $elm.off();
|
|
0 commit comments