By utilizing event handlers like focus and blur, I managed to resolve this issue.
To view the solution, please check here.
myApp.directive('customFocus', ['uiGridConstants', 'uiGridEditConstants',
function(uiGridConstants, uiGridEditConstants) {
return {
require: ['?^uiGrid', '?^uiGridRenderContainer'],
scope: true,
restrict: 'E',
template: '<div><div>Some text</div><input type="text"></div>',
link: function($scope, element, attrs, controllers) {
console.log(element);
console.log(arguments);
setTimeout(function() {
angular.element($(element).children().children()[1])[0].focus();
angular.element($(element).children().children()[1])[0].select();
}, 10);
var uiGridCtrl = controllers[0];
var renderContainerCtrl = controllers[1];
// Set focus at the beginning of edit
$scope.$on(uiGridEditConstants.events.BEGIN_CELL_EDIT, function() {
var thisEle = angular.element($(element).children().children()[1])[0];
thisEle.focus();
thisEle.select();
thisEle.style.width = (thisEle.parentElement.offsetWidth - 1) + 'px';
element.on('blur', function(evt) {
console.log("blur - element");
$scope.stopEdit(evt);
});
});
$scope.stopEdit = function(evt) {
$scope.$emit(uiGridEditConstants.events.END_CELL_EDIT);
};
element.on('keydown', function(evt) {
switch (evt.keyCode) {
case uiGridConstants.keymap.ESC:
evt.stopPropagation();
$scope.$emit(uiGridEditConstants.events.CANCEL_CELL_EDIT);
break;
}
if (uiGridCtrl && uiGridCtrl.grid.api.cellNav) {
evt.uiGridTargetRenderContainerId = renderContainerCtrl.containerId;
if (uiGridCtrl.cellNav.handleKeyDown(evt) !== null) {
$scope.stopEdit(evt);
}
} else {
switch (evt.keyCode) {
case uiGridConstants.keymap.ENTER:
case uiGridConstants.keymap.TAB:
evt.stopPropagation();
evt.preventDefault();
$scope.stopEdit(evt);
break;
}
}
return true;
});
}
}
}
]);