Skip to content

Commit 869be69

Browse files
committed
Merge pull request #3515 from PaulL1/fixes2
Fixes2
2 parents 4888a7c + aadc952 commit 869be69

File tree

7 files changed

+48
-12
lines changed

7 files changed

+48
-12
lines changed

misc/tutorial/102_sorting.ngdoc

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ data has changed by calling `gridApi.core.notifyDataChange( uiGridConstants.data
2525
If you set a default sort, you can prevent the user from removing that sort by setting `suppressRemoveSort: true`
2626
for that column. This will let the user change the direction of the sort, but take away the option to remove the sort.
2727

28+
The sort algorithm is chosen based on the column type. ui-grid will guess the type based on the data, although if you load data
29+
asynchronously after the columns it will often decide all your columns are string. You can explicitly set the column type in the
30+
column def using `type='number'`. Valid types are documented in {@link api/ui.grid.class:GridOptions.columnDef columnDef}, and
31+
include `string`, `number`, `numberStr` and `date`. If you use date be aware the code expects a javascript date object.
32+
2833
<example module="app">
2934
<file name="app.js">
3035
var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid']);

misc/tutorial/215_treeView.ngdoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ the tree.
1717

1818
TreeView is still alpha, and under development, however it is included in the distribution files
1919
to allow people to start using it. Notable outstandings are:
20-
- doesn't calculate or display counts of child nodes anywhere, it would be nice if it did
20+
- calculates but doesn't display counts of child nodes anywhere, it would be nice if it did
2121
- it would be nice to display an hourglass or icon whilst additional data was loading, the current
2222
arrangement means the grid doesn't know whether or not you're adding additional data
2323
- perhaps we could permit sorting of the nodes, and the children within each node, rather than sorting the
2424
whole data set. This would be a whole new sort algorithm though
25-
- it might be nice if nodes with no children could have their + removed, we'd need some way to be sure
26-
that these weren't nodes for which children are going to be dynamically loaded
2725

2826
Options to watch out for include:
2927

3028
- `treeViewIndent`: the expand buttons are indented by a number of pixels (default 10) as the tree
3129
level gets deeper. Larger values look nicer
3230
- `treeViewRowHeaderWidth`: the width of the tree row header
31+
- `showTreeExpandNoChildren`: defaults to true. Shows the + even if there are no children, allows
32+
you to dynamically load children. If set to false there'll be no + if there are no children
3333

3434
@example
3535
In this example most of the data is loaded on initial page load. The nodes under Guerrero Lopez, however,

src/features/edit/js/gridEdit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@
10431043

10441044
/**
10451045
* @ngdoc directive
1046-
* @name ui.grid.edit.directive:uiGridEditor
1046+
* @name ui.grid.edit.directive:uiGridEditFileChooser
10471047
* @element div
10481048
* @restrict A
10491049
*

src/features/tree-view/js/tree-view.js

+36-5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
* will run a rowsProcessor to set expand buttons alongside these nodes, and will maintain the
2222
* expand/collapse state of each node.
2323
*
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.
2726
*
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.
2929
*
3030
* Optionally the treeView can be populated only when nodes are clicked on. This will provide callbacks when
3131
* nodes are expanded, requesting the additional data. The node will be set to expanded, and when the data
@@ -358,6 +358,17 @@
358358
* <br/>Defaults to true
359359
*/
360360
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;
361372
},
362373

363374

@@ -586,6 +597,9 @@
586597
row.visible = true;
587598
}
588599

600+
// increment the child count on the parent
601+
service.incrementChildCount(parents);
602+
589603
// if this row is a node, then add it to the parents array
590604
if ( typeof(row.treeLevel) !== 'undefined' && row.treeLevel > -1 ){
591605
service.addOrUseState(grid, row, parents);
@@ -630,12 +644,14 @@
630644
grid.treeView.rowExpandedStates[row.uid] = { state: uiGridTreeViewConstants.COLLAPSED, row: row };
631645
}
632646
row.treeExpandedState = grid.treeView.rowExpandedStates[row.uid];
647+
row.treeExpandedState.childCount = 0;
633648
} else {
634649
var parentState = parents[parents.length - 1].treeExpandedState;
635650
if ( typeof(parentState[row.uid]) === 'undefined') {
636651
parentState[row.uid] = { state: uiGridTreeViewConstants.COLLAPSED, row: row };
637652
}
638653
row.treeExpandedState = parentState[row.uid];
654+
row.treeExpandedState.childCount = 0;
639655
}
640656
parents.push(row);
641657
},
@@ -661,8 +677,23 @@
661677
});
662678

663679
return currentState;
664-
}
680+
},
665681

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+
}
666697
};
667698

668699
return service;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<div class="ui-grid-tree-view-row-header-buttons" ng-class="{'ui-grid-tree-view-header': row.treeLevel > - 1}" ng-click="treeViewButtonClick(row, $event)">
2-
<i ng-class="{'ui-grid-icon-minus-squared': row.treeExpandedState.state === 'expanded', 'ui-grid-icon-plus-squared': row.treeExpandedState.state === 'collapsed'}" ng-style="{'padding-left': grid.options.treeViewIndent * row.entity.$$treeLevel + 'px'}"></i>
2+
<i ng-class="{'ui-grid-icon-minus-squared': ( grid.options.showTreeExpandNoChildren || row.treeExpandedState.childCount > 0 ) && row.treeExpandedState.state === 'expanded', 'ui-grid-icon-plus-squared': ( grid.options.showTreeExpandNoChildren || row.treeExpandedState.childCount > 0 ) && row.treeExpandedState.state === 'collapsed'}" ng-style="{'padding-left': grid.options.treeViewIndent * row.entity.$$treeLevel + 'px'}"></i>
33
&nbsp;
44
</div>

src/features/tree-view/test/tree-view.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
describe('ui.grid.treeView uiGridTreeViewService', function () {
1+
ddescribe('ui.grid.treeView uiGridTreeViewService', function () {
22
var uiGridTreeViewService;
33
var uiGridTreeViewConstants;
44
var gridClassFactory;

src/js/core/directives/ui-grid-menu.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
* @ngdoc directive
5-
* @name ui.grid.directive:uiGridColumnMenu
5+
* @name ui.grid.directive:uiGridMenu
66
* @element style
77
* @restrict A
88
*

0 commit comments

Comments
 (0)