Skip to content

Commit

Permalink
Merge pull request #3515 from PaulL1/fixes2
Browse files Browse the repository at this point in the history
Fixes2
  • Loading branch information
PaulL1 committed May 16, 2015
2 parents 4888a7c + aadc952 commit 869be69
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 12 deletions.
5 changes: 5 additions & 0 deletions misc/tutorial/102_sorting.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ data has changed by calling `gridApi.core.notifyDataChange( uiGridConstants.data
If you set a default sort, you can prevent the user from removing that sort by setting `suppressRemoveSort: true`
for that column. This will let the user change the direction of the sort, but take away the option to remove the sort.

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
asynchronously after the columns it will often decide all your columns are string. You can explicitly set the column type in the
column def using `type='number'`. Valid types are documented in {@link api/ui.grid.class:GridOptions.columnDef columnDef}, and
include `string`, `number`, `numberStr` and `date`. If you use date be aware the code expects a javascript date object.

<example module="app">
<file name="app.js">
var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid']);
Expand Down
6 changes: 3 additions & 3 deletions misc/tutorial/215_treeView.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ the tree.

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

Options to watch out for include:

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

@example
In this example most of the data is loaded on initial page load. The nodes under Guerrero Lopez, however,
Expand Down
2 changes: 1 addition & 1 deletion src/features/edit/js/gridEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@

/**
* @ngdoc directive
* @name ui.grid.edit.directive:uiGridEditor
* @name ui.grid.edit.directive:uiGridEditFileChooser
* @element div
* @restrict A
*
Expand Down
41 changes: 36 additions & 5 deletions src/features/tree-view/js/tree-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
* will run a rowsProcessor to set expand buttons alongside these nodes, and will maintain the
* expand/collapse state of each node.
*
* In future a count of the direct children of each node could optionally be calculated and displayed
* alongside the node - the current issue is deciding where to display that. For now we calculate it
* but don't display it.
* A count of the direct children of each node is calculated in the expanded states, the current
* issue is deciding where to display that. For now we calculate it but don't display it.
*
* In future the count could be used to remove the + from a row that doesn't actually have any children.
* The count can be used to remove the + from a row that doesn't actually have any children, if you
* set the option treeHideNoChildren.
*
* Optionally the treeView can be populated only when nodes are clicked on. This will provide callbacks when
* nodes are expanded, requesting the additional data. The node will be set to expanded, and when the data
Expand Down Expand Up @@ -358,6 +358,17 @@
* <br/>Defaults to true
*/
gridOptions.showTreeViewRowHeader = gridOptions.showTreeViewRowHeader !== false;

/**
* @ngdoc object
* @name showTreeExpandNoChildren
* @propertyOf ui.grid.treeView.api:GridOptions
* @description If set to true, show the expand/collapse button even if there are no
* children of a node. You'd use this if you're planning to dynamically load the children
*
* <br/>Defaults to true
*/
gridOptions.showTreeExpandNoChildren = gridOptions.showTreeExpandNoChildren !== false;
},


Expand Down Expand Up @@ -586,6 +597,9 @@
row.visible = true;
}

// increment the child count on the parent
service.incrementChildCount(parents);

// if this row is a node, then add it to the parents array
if ( typeof(row.treeLevel) !== 'undefined' && row.treeLevel > -1 ){
service.addOrUseState(grid, row, parents);
Expand Down Expand Up @@ -630,12 +644,14 @@
grid.treeView.rowExpandedStates[row.uid] = { state: uiGridTreeViewConstants.COLLAPSED, row: row };
}
row.treeExpandedState = grid.treeView.rowExpandedStates[row.uid];
row.treeExpandedState.childCount = 0;
} else {
var parentState = parents[parents.length - 1].treeExpandedState;
if ( typeof(parentState[row.uid]) === 'undefined') {
parentState[row.uid] = { state: uiGridTreeViewConstants.COLLAPSED, row: row };
}
row.treeExpandedState = parentState[row.uid];
row.treeExpandedState.childCount = 0;
}
parents.push(row);
},
Expand All @@ -661,8 +677,23 @@
});

return currentState;
}
},


/**
* @ngdoc function
* @name incrementChildCount
* @methodOf ui.grid.treeView.service:uiGridTreeViewService
* @description Increments the child count of the lowest node in the parents array.
*
* @param {array} parents an array of the parents this row should have
* @returns {string} the state we should be setting to any nodes we see
*/
incrementChildCount: function( parents ){
if ( parents.length > 0 ){
parents[parents.length - 1].treeExpandedState.childCount++;
}
}
};

return service;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="ui-grid-tree-view-row-header-buttons" ng-class="{'ui-grid-tree-view-header': row.treeLevel > - 1}" ng-click="treeViewButtonClick(row, $event)">
<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>
<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>
&nbsp;
</div>
2 changes: 1 addition & 1 deletion src/features/tree-view/test/tree-view.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
describe('ui.grid.treeView uiGridTreeViewService', function () {
ddescribe('ui.grid.treeView uiGridTreeViewService', function () {
var uiGridTreeViewService;
var uiGridTreeViewConstants;
var gridClassFactory;
Expand Down
2 changes: 1 addition & 1 deletion src/js/core/directives/ui-grid-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* @ngdoc directive
* @name ui.grid.directive:uiGridColumnMenu
* @name ui.grid.directive:uiGridMenu
* @element style
* @restrict A
*
Expand Down

0 comments on commit 869be69

Please sign in to comment.