右键单击单元格上的角度ui网格自定义菜单



我正在使用Angular ui网格,并有以下要求:

  • 右键单击网格的任何特定"CELL/Column"时显示自定义菜单,例如下图中的"B">
  • 右键单击时,自定义菜单将始终显示单个选项"COPY",该选项将复制值并将其粘贴到下面的单元格中

样本图像

function SampleRightClickController($scope, $rootScope, $timeout){
$scope.gridOptions = {data: myData};
$scope.rightClick = function (event) {
var scope = angular.element(event.toElement).scope()
console.log('you clicked on row: ', scope.rowRenderIndex);
};
}]);
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});
});
});
};
});
}
})();
HTML:
<div class="gridStyle" ui-grid="gridOptions" ui-grid-selection ui-grid-edit ui-grid-cellNav right-click="rightClick($event);"></div>

尝试了上面的代码,但它只右键单击"ROW"而不是"Column"。有人能帮我如何使用angular ui grid获得以上2个要求吗?

您可以通过使用上下文菜单来实现这一点。请看下面。

https://github.com/Templarian/ui.bootstrap.contextMenu

最新更新