Is there a way to select the row when a right click occurs on it?
I came across a potential solution (inspired by this discussion):
By creating a custom directive for right-click functionality:
app.directive('rightClick', function($parse) {
return function(scope, element, attrs) {
var fn = $parse(attrs.rightClick);
element.bind('contextmenu', function(event) {
scope.$apply(function() {
event.preventDefault();
fn(scope, {$event:event});
});
});
};
});
Next, a corresponding function can be added in the controller to handle the right-click event:
$scope.rightClick = function (event) {
var scope = angular.element(event.toElement).scope();
if (scope.row.entity !== undefined) {
//... code to select the element using gridApi
}
};
Don't forget to use the directive with the attribute right-click="rightClick($event)"
.
The drawback of this approach is that it relies on element.scope()
, which is a debugging feature of Angular and may not be available when debug information is disabled in a production environment.
Hence, I am seeking an alternative method that does not depend on element.scope()
. The question then becomes: "How can I achieve row selection on right-click without relying on Angular's debug features?"