VERSION:
I am using Angular ui-grid version 3.0.0-RC.18 (http://ui-grid.info/).
PROBLEM
I want to implement a double-click event in an ui-grid table. In particular, I want to open a modal pop-up when double-clicking at a row.
I tried to use a ng-dblclick directive inside the rowTemplate definition as is suggested at https://github.com/angular-ui/ng-grid/issues/2228 , but 'dblclick' event is never fired.
Nevertheless, I found a solution, but using a directive created by my own. Can I do it better, without creating a directive?
Any comment would be appreciated.
CODE:
My code at the Controller is as follows:
$scope.onDblClick = function(row) {
var url = '//google.com';
$window.open(url, "_blank", "height=600,width=800,toolbar=no,location=no,menubar=no,titlebar=no");
}
// Define the New Conflicts Simulation GRID behavior
$scope.myGridOptions = {
showFooter: false,
enableSorting: true,
multiSelect: false,
enableFiltering: true,
enableRowSelection: true,
enableSelectAll: false,
enableRowHeaderSelection: false,
enableGridMenu: true,
noUnselect: true,
onRegisterApi: function (gridApi){
$scope.gridApi = gridApi;
},
rowTemplate: "<div ng-dblclick=\"onDblClick(row)\" ng-repeat=\"(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name\" class=\"ui-grid-cell\" ng-class=\"{ 'ui-grid-row-header-cell': col.isRowHeader }\" ui-grid-cell dbl-click-row></div>"
}
(Where dbl-click-row indicates I am using the dblClickRow directive)
My code at the View is as follows:
<div id="myGrid" ui-grid="myGridOptions" ui-grid-selection ui-grid-resize-columns class="gridTable" ></div>
My code at the Directive is as follows:
var angularStartDirectives = angular.module('angularStart.directives', []);
angularStartDirectives.directive('dblClickRow', ['$compile', '$parse', function($compile, $parse) {
return {
priority : -190, // run after default uiGridCell directive
restrict : 'A',
scope : false,
compile: function($element, attr) {
// Get the function at ng-dblclick for ui-grid
var fn = $parse(attr['ngDblclick'], /* interceptorFn */ null, /* expensiveChecks */ true);
return function ngEventHandler(scope, element) {
element.on('dblclick', function(event) {
var callback = function() {
if ($scope.gridApi.grid.selection.lastSelectedRow)
{
fn($scope, {$event:event, row: $scope.gridApi.grid.selection.lastSelectedRow.entity });
}
};
$scope.$apply(callback);
}
)};
}
};
} ]);