|
23 | 23 | * |
24 | 24 | * @description Services for the expandable grid |
25 | 25 | */ |
26 | | - module.service('uiGridExpandableService', ['gridUtil', '$compile', function (gridUtil, $compile) { |
| 26 | + module.service('uiGridExpandableService', ['gridUtil', function (gridUtil) { |
27 | 27 | var service = { |
28 | 28 | initializeGrid: function (grid) { |
29 | 29 |
|
30 | 30 | grid.expandable = {}; |
31 | 31 | grid.expandable.expandedAll = false; |
32 | 32 |
|
33 | 33 | /** |
34 | | - * @ngdoc object |
| 34 | + * @ngdoc boolean |
| 35 | + * @name enableOnDblClickExpand |
| 36 | + * @propertyOf ui.grid.expandable.api:GridOptions |
| 37 | + * @description Defaults to true. |
| 38 | + * @example |
| 39 | + * <pre> |
| 40 | + * $scope.gridOptions = { |
| 41 | + * onDblClickExpand: false |
| 42 | + * } |
| 43 | + * </pre> |
| 44 | + */ |
| 45 | + grid.options.enableOnDblClickExpand = grid.options.enableOnDblClickExpand !== false; |
| 46 | + /** |
| 47 | + * @ngdoc boolean |
35 | 48 | * @name enableExpandable |
36 | 49 | * @propertyOf ui.grid.expandable.api:GridOptions |
37 | 50 | * @description Whether or not to use expandable feature, allows you to turn off expandable on specific grids |
|
134 | 147 | * @eventOf ui.grid.expandable.api:PublicApi |
135 | 148 | * @description raised when row is expanding or collapsing |
136 | 149 | * <pre> |
137 | | - * gridApi.expandable.on.rowExpandedBeforeStateChanged(scope,function(row){}) |
| 150 | + * gridApi.expandable.on.rowExpandedBeforeStateChanged(scope,function(row, event){}) |
138 | 151 | * </pre> |
139 | 152 | * @param {scope} scope the application scope |
140 | 153 | * @param {GridRow} row the row that was expanded |
| 154 | + * @param {Event} evt object if raised from an event |
141 | 155 | */ |
142 | | - rowExpandedBeforeStateChanged: function(scope, row){ |
143 | | - }, |
| 156 | + rowExpandedBeforeStateChanged: function(scope, row, evt){}, |
| 157 | + |
144 | 158 | /** |
145 | 159 | * @ngdoc event |
146 | 160 | * @name rowExpandedStateChanged |
147 | 161 | * @eventOf ui.grid.expandable.api:PublicApi |
148 | 162 | * @description raised when row expanded or collapsed |
149 | 163 | * <pre> |
150 | | - * gridApi.expandable.on.rowExpandedStateChanged(scope,function(row){}) |
| 164 | + * gridApi.expandable.on.rowExpandedStateChanged(scope,function(row, event){}) |
151 | 165 | * </pre> |
152 | 166 | * @param {scope} scope the application scope |
153 | 167 | * @param {GridRow} row the row that was expanded |
| 168 | + * @param {Event} evt object if raised from an event |
154 | 169 | */ |
155 | | - rowExpandedStateChanged: function (scope, row) { |
156 | | - } |
| 170 | + rowExpandedStateChanged: function (scope, row, evt) {}, |
| 171 | + |
| 172 | + /** |
| 173 | + * @ngdoc event |
| 174 | + * @name rowExpandedRendered |
| 175 | + * @eventOf ui.grid.expandable.api:PublicApi |
| 176 | + * @description raised when expanded row is rendered |
| 177 | + * <pre> |
| 178 | + * gridApi.expandable.on.rowExpandedRendered(scope,function(row, event){}) |
| 179 | + * </pre> |
| 180 | + * @param {scope} scope the application scope |
| 181 | + * @param {GridRow} row the row that was expanded |
| 182 | + * @param {Event} evt object if raised from an event |
| 183 | + */ |
| 184 | + rowExpandedRendered: function (scope, row, evt) {} |
157 | 185 | } |
158 | 186 | }, |
159 | 187 |
|
|
165 | 193 | * @methodOf ui.grid.expandable.api:PublicApi |
166 | 194 | * @description Toggle a specific row |
167 | 195 | * <pre> |
168 | | - * gridApi.expandable.toggleRowExpansion(rowEntity); |
| 196 | + * gridApi.expandable.toggleRowExpansion(rowEntity, event); |
169 | 197 | * </pre> |
170 | 198 | * @param {object} rowEntity the data entity for the row you want to expand |
| 199 | + * @param {Event} [e] event (if exist) |
171 | 200 | */ |
172 | | - toggleRowExpansion: function (rowEntity) { |
| 201 | + toggleRowExpansion: function (rowEntity, e) { |
173 | 202 | var row = grid.getRow(rowEntity); |
174 | 203 | if (row !== null) { |
175 | | - service.toggleRowExpansion(grid, row); |
| 204 | + service.toggleRowExpansion(grid, row, e); |
176 | 205 | } |
177 | 206 | }, |
178 | 207 |
|
|
258 | 287 | grid.api.registerMethodsFromObject(publicApi.methods); |
259 | 288 | }, |
260 | 289 |
|
261 | | - toggleRowExpansion: function (grid, row) { |
| 290 | + /** |
| 291 | + * |
| 292 | + * @param grid |
| 293 | + * @param row |
| 294 | + * @param {Event} [e] event (if exist) |
| 295 | + */ |
| 296 | + toggleRowExpansion: function (grid, row, e) { |
262 | 297 | // trigger the "before change" event. Can change row height dynamically this way. |
263 | 298 | grid.api.expandable.raise.rowExpandedBeforeStateChanged(row); |
264 | 299 | /** |
|
287 | 322 | row.height = row.grid.options.rowHeight; |
288 | 323 | grid.expandable.expandedAll = false; |
289 | 324 | } |
290 | | - grid.api.expandable.raise.rowExpandedStateChanged(row); |
| 325 | + grid.api.expandable.raise.rowExpandedStateChanged(row, e); |
| 326 | + |
| 327 | + // fire event on render complete |
| 328 | + function _tWatcher(){ |
| 329 | + if (row.expandedRendered) { |
| 330 | + grid.api.expandable.raise.rowExpandedRendered(row, e); |
| 331 | + } else { |
| 332 | + window.setTimeout(_tWatcher, 1e2); |
| 333 | + } |
| 334 | + } |
| 335 | + _tWatcher(); |
291 | 336 | }, |
292 | 337 |
|
293 | 338 | expandAllRows: function(grid) { |
|
341 | 386 | * } |
342 | 387 | * </pre> |
343 | 388 | */ |
| 389 | + |
344 | 390 | module.directive('uiGridExpandable', ['uiGridExpandableService', '$templateCache', |
345 | 391 | function (uiGridExpandableService, $templateCache) { |
346 | 392 | return { |
|
364 | 410 | exporterSuppressExport: true, |
365 | 411 | enableColumnResizing: false, |
366 | 412 | enableColumnMenu: false, |
367 | | - width: uiGridCtrl.grid.options.expandableRowHeaderWidth || 40 |
| 413 | + width: uiGridCtrl.grid.options.expandableRowHeaderWidth || 30 |
368 | 414 | }; |
369 | 415 | expandableRowHeaderColDef.cellTemplate = $templateCache.get('ui-grid/expandableRowHeader'); |
370 | 416 | expandableRowHeaderColDef.headerCellTemplate = $templateCache.get('ui-grid/expandableTopRowHeader'); |
371 | 417 | uiGridCtrl.grid.addRowHeaderColumn(expandableRowHeaderColDef, -90); |
372 | 418 | } |
373 | | - |
374 | 419 | }, |
375 | | - post: function ($scope, $elm, $attrs, uiGridCtrl) { |
376 | | - } |
| 420 | + post: function ($scope, $elm, $attrs, uiGridCtrl) {} |
377 | 421 | }; |
378 | 422 | } |
379 | 423 | }; |
|
397 | 441 |
|
398 | 442 | uiGridCtrl.grid.api.core.on.renderingComplete($scope, function() { |
399 | 443 | //if a parent grid row is on the scope, then add the parentRow property to this childGrid |
400 | | - if ($scope.row && $scope.row.grid && $scope.row.grid.options && $scope.row.grid.options.enableExpandable) { |
| 444 | + if ($scope.row && $scope.row.grid && $scope.row.grid.options |
| 445 | + && $scope.row.grid.options.enableExpandable) { |
401 | 446 |
|
402 | 447 | /** |
403 | 448 | * @ngdoc directive |
|
418 | 463 | // uiGridCtrl.grid.parentRow = newHeight; |
419 | 464 | // }); |
420 | 465 | } |
421 | | - |
422 | 466 | }); |
423 | 467 | }, |
424 | | - post: function ($scope, $elm, $attrs, uiGridCtrl) { |
425 | | - |
426 | | - } |
| 468 | + post: function ($scope, $elm, $attrs, uiGridCtrl) {} |
427 | 469 | }; |
428 | 470 | } |
429 | 471 | }; |
|
432 | 474 | /** |
433 | 475 | * @ngdoc directive |
434 | 476 | * @name ui.grid.expandable.directive:uiGridExpandableRow |
435 | | - * @description directive to render the expandable row template |
| 477 | + * @description directive to render the Row template on Expand |
436 | 478 | */ |
437 | 479 | module.directive('uiGridExpandableRow', |
438 | | - ['uiGridExpandableService', '$timeout', '$compile', 'uiGridConstants','gridUtil','$interval', '$log', |
439 | | - function (uiGridExpandableService, $timeout, $compile, uiGridConstants, gridUtil, $interval, $log) { |
| 480 | + ['uiGridExpandableService', '$compile', 'uiGridConstants','gridUtil', |
| 481 | + function (uiGridExpandableService, $compile, uiGridConstants, gridUtil) { |
440 | 482 |
|
441 | 483 | return { |
442 | 484 | replace: false, |
443 | 485 | priority: 0, |
444 | 486 | scope: false, |
445 | | - |
446 | 487 | compile: function () { |
447 | 488 | return { |
448 | 489 | pre: function ($scope, $elm, $attrs, uiGridCtrl) { |
|
469 | 510 | } |
470 | 511 | } |
471 | 512 | var expandedRowElement = angular.element(template); |
472 | | - $elm.append(expandedRowElement); |
| 513 | + |
473 | 514 | expandedRowElement = $compile(expandedRowElement)($scope); |
| 515 | + $elm.append(expandedRowElement); |
| 516 | + $scope.row.element = $elm; |
474 | 517 | $scope.row.expandedRendered = true; |
475 | 518 | }); |
476 | 519 | }, |
477 | 520 |
|
478 | 521 | post: function ($scope, $elm, $attrs, uiGridCtrl) { |
| 522 | + $scope.row.element = $elm; |
479 | 523 | $scope.$on('$destroy', function() { |
480 | 524 | $scope.row.expandedRendered = false; |
481 | 525 | }); |
|
507 | 551 | $scope.expandableRow = {}; |
508 | 552 |
|
509 | 553 | $scope.expandableRow.shouldRenderExpand = function () { |
510 | | - var ret = $scope.colContainer.name === 'body' && $scope.grid.options.enableExpandable !== false && $scope.row.isExpanded && (!$scope.grid.isScrollingVertically || $scope.row.expandedRendered); |
511 | | - return ret; |
| 554 | + return $scope.colContainer.name === 'body' |
| 555 | + && $scope.grid.options.enableExpandable !== false |
| 556 | + && $scope.row.isExpanded |
| 557 | + && (!$scope.grid.isScrollingVertically || $scope.row.expandedRendered); |
512 | 558 | }; |
513 | 559 |
|
514 | 560 | $scope.expandableRow.shouldRenderFiller = function () { |
515 | | - var ret = $scope.row.isExpanded && ( $scope.colContainer.name !== 'body' || ($scope.grid.isScrollingVertically && !$scope.row.expandedRendered)); |
516 | | - return ret; |
| 561 | + return $scope.row.isExpanded |
| 562 | + && ( |
| 563 | + $scope.colContainer.name !== 'body' |
| 564 | + || ($scope.grid.isScrollingVertically && !$scope.row.expandedRendered)); |
517 | 565 | }; |
518 | 566 |
|
| 567 | + if ($scope.grid.options.enableOnDblClickExpand) { |
| 568 | + $elm.on('dblclick', function (event) { |
| 569 | + // if necessary, it is possible for everyone to stop the processing of a single click OR |
| 570 | + // Inside the Config in the output agent to enter a line: |
| 571 | + // event.stopPropagation() |
| 572 | + $scope.grid.api.expandable.toggleRowExpansion($scope.row.entity, event); |
| 573 | + }); |
| 574 | + } |
| 575 | + |
519 | 576 | /* |
520 | 577 | * Commented out @PaulL1. This has no purpose that I can see, and causes #2964. If this code needs to be reinstated for some |
521 | 578 | * reason it needs to use drawnWidth, not width, and needs to check column visibility. It should really use render container |
|
542 | 599 | }*/ |
543 | 600 |
|
544 | 601 | }, |
545 | | - post: function ($scope, $elm, $attrs, controllers) { |
546 | | - } |
| 602 | + post: function ($scope, $elm, $attrs, controllers) {} |
547 | 603 | }; |
548 | 604 | } |
549 | 605 | }; |
|
0 commit comments