|
21 | 21 | * will run a rowsProcessor to set expand buttons alongside these nodes, and will maintain the
|
22 | 22 | * expand/collapse state of each node.
|
23 | 23 | *
|
24 |
| - * In future a count of the direct children of each node could optionally be calculated and displayed |
25 |
| - * alongside the node - the current issue is deciding where to display that. For now we calculate it |
26 |
| - * but don't display it. |
| 24 | + * A count of the direct children of each node is calculated in the expanded states, the current |
| 25 | + * issue is deciding where to display that. For now we calculate it but don't display it. |
27 | 26 | *
|
28 |
| - * In future the count could be used to remove the + from a row that doesn't actually have any children. |
| 27 | + * The count can be used to remove the + from a row that doesn't actually have any children, if you |
| 28 | + * set the option treeHideNoChildren. |
29 | 29 | *
|
30 | 30 | * Optionally the treeView can be populated only when nodes are clicked on. This will provide callbacks when
|
31 | 31 | * nodes are expanded, requesting the additional data. The node will be set to expanded, and when the data
|
|
358 | 358 | * <br/>Defaults to true
|
359 | 359 | */
|
360 | 360 | gridOptions.showTreeViewRowHeader = gridOptions.showTreeViewRowHeader !== false;
|
| 361 | + |
| 362 | + /** |
| 363 | + * @ngdoc object |
| 364 | + * @name showTreeExpandNoChildren |
| 365 | + * @propertyOf ui.grid.treeView.api:GridOptions |
| 366 | + * @description If set to true, show the expand/collapse button even if there are no |
| 367 | + * children of a node. You'd use this if you're planning to dynamically load the children |
| 368 | + * |
| 369 | + * <br/>Defaults to true |
| 370 | + */ |
| 371 | + gridOptions.showTreeExpandNoChildren = gridOptions.showTreeExpandNoChildren !== false; |
361 | 372 | },
|
362 | 373 |
|
363 | 374 |
|
|
586 | 597 | row.visible = true;
|
587 | 598 | }
|
588 | 599 |
|
| 600 | + // increment the child count on the parent |
| 601 | + service.incrementChildCount(parents); |
| 602 | + |
589 | 603 | // if this row is a node, then add it to the parents array
|
590 | 604 | if ( typeof(row.treeLevel) !== 'undefined' && row.treeLevel > -1 ){
|
591 | 605 | service.addOrUseState(grid, row, parents);
|
|
630 | 644 | grid.treeView.rowExpandedStates[row.uid] = { state: uiGridTreeViewConstants.COLLAPSED, row: row };
|
631 | 645 | }
|
632 | 646 | row.treeExpandedState = grid.treeView.rowExpandedStates[row.uid];
|
| 647 | + row.treeExpandedState.childCount = 0; |
633 | 648 | } else {
|
634 | 649 | var parentState = parents[parents.length - 1].treeExpandedState;
|
635 | 650 | if ( typeof(parentState[row.uid]) === 'undefined') {
|
636 | 651 | parentState[row.uid] = { state: uiGridTreeViewConstants.COLLAPSED, row: row };
|
637 | 652 | }
|
638 | 653 | row.treeExpandedState = parentState[row.uid];
|
| 654 | + row.treeExpandedState.childCount = 0; |
639 | 655 | }
|
640 | 656 | parents.push(row);
|
641 | 657 | },
|
|
661 | 677 | });
|
662 | 678 |
|
663 | 679 | return currentState;
|
664 |
| - } |
| 680 | + }, |
665 | 681 |
|
| 682 | + |
| 683 | + /** |
| 684 | + * @ngdoc function |
| 685 | + * @name incrementChildCount |
| 686 | + * @methodOf ui.grid.treeView.service:uiGridTreeViewService |
| 687 | + * @description Increments the child count of the lowest node in the parents array. |
| 688 | + * |
| 689 | + * @param {array} parents an array of the parents this row should have |
| 690 | + * @returns {string} the state we should be setting to any nodes we see |
| 691 | + */ |
| 692 | + incrementChildCount: function( parents ){ |
| 693 | + if ( parents.length > 0 ){ |
| 694 | + parents[parents.length - 1].treeExpandedState.childCount++; |
| 695 | + } |
| 696 | + } |
666 | 697 | };
|
667 | 698 |
|
668 | 699 | return service;
|
|
0 commit comments