Skip to content

Commit 1426454

Browse files
committed
fix(cellNav): If cellNav api exists, turn on stuff
There was a bug caused by a combination of cellNav and subgrids. If the parent grid had cellNav turned on but the subgrids didn't, they would still attach event handlers for cellNav because the directive was looking for the cellNav controller in its parent chain. It existed, but on the wrong grid. This change looks for the presence of the cellNav api in the Grid to turn on the event handlers. Fixes #2294
1 parent d6eec4c commit 1426454

File tree

2 files changed

+85
-10
lines changed

2 files changed

+85
-10
lines changed

Diff for: misc/demo/subgrid.html

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<!DOCTYPE html>
2+
<html class="no-js" ng-app="test"><!--<![endif]-->
3+
<head>
4+
<meta charset="utf-8">
5+
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
6+
<title></title>
7+
<meta content="width=device-width" name="viewport">
8+
9+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" />
10+
<link href="/dist/release/ui-grid.css" rel="stylesheet">
11+
12+
<script src="//code.jquery.com/jquery-2.1.3.min.js"></script>
13+
<script src="/lib/test/angular/1.2.26/angular.js"></script>
14+
<script src="/dist/release/ui-grid.js"></script>
15+
16+
<style>
17+
body {
18+
padding: 60px;
19+
min-height: 600px;
20+
}
21+
.grid {
22+
width: 500px;
23+
height: 400px;
24+
}
25+
.placeholder {
26+
height: 50%;
27+
width: 50%;
28+
border: 3px solid black;
29+
background: #ccc;
30+
}
31+
</style>
32+
</head>
33+
<body ng-controller="Main">
34+
<!-- <h1>Test</h1> -->
35+
36+
<!-- <div class="row main"> -->
37+
<h2>Grid</h2>
38+
<button type="button" ng-click="swap()">Swap Columns</button>
39+
<br>
40+
<br>
41+
<div ui-grid="gridOptions" class="grid" ui-grid-cellnav ui-grid-expandable></div>
42+
<!-- <div class="placeholder"> -->
43+
<!-- </div> -->
44+
45+
<br>
46+
<br>
47+
48+
<script>
49+
var app = angular.module('test', ['ui.grid', 'ui.grid.expandable', 'ui.grid.cellNav']);
50+
app.controller('Main', function($scope, $http) {
51+
$scope.gridOptions = {
52+
expandableRowTemplate: 'subgrid',
53+
expandableRowHeight: 150,
54+
};
55+
$scope.gridOptions.columnDefs = [
56+
{ field:'id' },
57+
{ field:'name' },
58+
{ field:'age' }
59+
];
60+
61+
$http.get('https://rawgit.com/angular-ui/ui-grid.info/gh-pages/data/500_complex.json')
62+
.success(function(data) {
63+
data.forEach(function (d) {
64+
d.subGridOptions = {
65+
columnDefs: [ { field: "company" }, { field: "email" } ],
66+
data: data.slice(0, 100)
67+
};
68+
});
69+
70+
$scope.gridOptions.data = data;
71+
});
72+
});
73+
</script>
74+
75+
<script type="text/ng-template" id="subgrid">
76+
<div ui-grid="row.entity.subGridOptions" style="height:140px;"></div>
77+
</script>
78+
79+
</body>
80+
</html>

Diff for: src/features/cellnav/js/cellnav.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -910,12 +910,10 @@
910910
return {
911911
post: function ($scope, $elm, $attrs, controllers) {
912912
var uiGridCtrl = controllers[0],
913-
renderContainerCtrl = controllers[1],
914-
cellNavController = controllers[2];
913+
renderContainerCtrl = controllers[1];
915914

916915
// Skip attaching cell-nav specific logic if the directive is not attached above us
917-
if (!cellNavController) { return; }
918-
916+
if (!uiGridCtrl.grid.api.cellNav) { return; }
919917

920918
var containerId = renderContainerCtrl.containerId;
921919

@@ -987,14 +985,11 @@
987985
return {
988986
priority: -150, // run after default uiGridCell directive and ui.grid.edit uiGridCell
989987
restrict: 'A',
990-
require: ['^uiGrid', '?^uiGridCellnav'],
988+
require: '^uiGrid',
991989
scope: false,
992-
link: function ($scope, $elm, $attrs, controllers) {
993-
var uiGridCtrl = controllers[0],
994-
cellNavController = controllers[1];
995-
990+
link: function ($scope, $elm, $attrs, uiGridCtrl) {
996991
// Skip attaching cell-nav specific logic if the directive is not attached above us
997-
if (!cellNavController) { return; }
992+
if (!uiGridCtrl.grid.api.cellNav) { return; }
998993

999994
if (!$scope.col.colDef.allowCellFocus) {
1000995
return;

0 commit comments

Comments
 (0)