Skip to content

Commit 7e36e81

Browse files
committed
Merge pull request khan4019#2 from khan4019/master
Updating from khan4019/tree-grid-directive
2 parents c9abc85 + a2cc10f commit 7e36e81

File tree

6 files changed

+866
-749
lines changed

6 files changed

+866
-749
lines changed

README.md

Lines changed: 110 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,26 @@ Feel free to whatever you want to do with it.
1010

1111
### Mininum to start
1212
--------------------
13-
Include `src/treeGrid.css` and `src/tree-grid-directive.js` in your HTML file after Bootstrap and Angular. Just add the following
13+
####EITHER:
14+
15+
Install with Bower
16+
17+
$ bower install angular-bootstrap-grid-tree
18+
19+
Install with Npm
20+
21+
$ npm install angular-bootstrap-grid-tree
22+
23+
####OR:
24+
Include `src/treeGrid.css` and `src/tree-grid-directive.js` in your HTML file after Bootstrap and Angular.
25+
26+
####THEN
27+
28+
Just add the following
1429

1530
<tree-grid tree-data="tree_data"></tree-grid>
1631

17-
Then include the module as a dependency in your application:
32+
Include the module as a dependency in your application:
1833

1934
angular.module('myApp', ['treeGrid'])
2035

@@ -109,7 +124,8 @@ Example:
109124
];
110125

111126
**expanding_property:** this is the property of the objects in `tree_data` where you want to put the ability to expand and collapse.
112-
This accepts an array of the same format as col_defs, allowing for sorting & filtering on the expanding field.
127+
This accepts an array of the same format as col_defs, allowing for sorting & filtering on the expanding field. This now includes the ability
128+
to provide a cellTemplate (but not a cellTemplateScope).
113129

114130
**my_tree:** you can use `tree-control` to use expand all and collapse all. Check it out in the link provided for demo.
115131

@@ -132,6 +148,89 @@ need to redirect if a branch is selected.
132148
console.log('you clicked on', branch)
133149
}
134150

151+
### Setting icons per row
152+
If the data contains different types, it may be useful to differentiate between them with different icons. Every row can set following three icons:
153+
154+
* **iconLeaf** the icon that will be shown if the row is a leaf
155+
* **iconCollapse** the icon that will be shown if the row has children and is expanded
156+
* **iconExpand** the icon that will be shown if the row has children and is collapsed
157+
158+
Every icon that **isn't** overriden will be the one defined at the tree-grid directive or the default one if none defined.
159+
160+
Example:
161+
```html
162+
<tree-grid
163+
tree-data = "tree_data"
164+
icon-leaf = "icon-file"
165+
icon-expand = "icon-plus-sign"
166+
icon-collapse = "icon-minus-sign"
167+
</tree-grid>
168+
```
169+
170+
```javascript
171+
$scope.tree_data = [
172+
{Name:"USA",Area:9826675,Population:318212000,TimeZone:"UTC -5 to -10",
173+
children:[
174+
{Name:"California", Area:423970,Population:38340000,TimeZone:"Pacific Time",
175+
children:[
176+
{Name:"San Francisco", Area:231,Population:837442,TimeZone:"PST"},
177+
{Name:"Los Angeles", Area:503,Population:3904657,TimeZone:"PST"}
178+
]
179+
icons: {
180+
iconLeaf: "fa fa-sun-o"
181+
}
182+
},
183+
{Name:"Illinois", Area:57914,Population:12882135,TimeZone:"Central Time Zone",
184+
children:[
185+
{Name:"Chicago", Area:234,Population:2695598,TimeZone:"CST"}
186+
]
187+
}
188+
],
189+
icons: {
190+
iconLeaf: "fa fa-flag",
191+
iconCollapse: "fa fa-folder-open",
192+
iconExpand: "fa fa-folder"
193+
}
194+
},
195+
{Name:"Texas",Area:268581,Population:26448193,TimeZone:"Mountain"}
196+
];
197+
```
198+
199+
### Expanding tree after search
200+
If it is desired to expand the tree after a (successful) search, you need to modify the template and add a **true** to the filter parameters.
201+
202+
<code>
203+
&lt;tr ng-repeat="row in tree_rows | searchFor:$parent.filterString:expandingProperty:colDefinitions:<b>true</b> track by row.branch.uid"&gt;
204+
</code>
205+
206+
Full example (based on original template):
207+
```html
208+
<div class="table-responsive">
209+
<table class="table tree-grid">
210+
<thead>
211+
<tr>
212+
<th><a ng-if="expandingProperty.sortable" ng-click="sortBy(expandingProperty)">{{expandingProperty.displayName || expandingProperty.field || expandingProperty}}</a><span ng-if="!expandingProperty.sortable">{{expandingProperty.displayName || expandingProperty.field || expandingProperty}}</span><i ng-if="expandingProperty.sorted" class="{{expandingProperty.sortingIcon}} pull-right"></i></th>
213+
<th ng-repeat="col in colDefinitions"><a ng-if="col.sortable" ng-click="sortBy(col)">{{col.displayName || col.field}}</a><span ng-if="!col.sortable">{{col.displayName || col.field}}</span><i ng-if="col.sorted" class="{{col.sortingIcon}} pull-right"></i></th>
214+
</tr>
215+
</thead>
216+
<tbody>
217+
<tr ng-repeat="row in tree_rows | searchFor:$parent.filterString:expandingProperty:colDefinitions:true track by row.branch.uid"
218+
ng-class="'level-' + {{ row.level }} + (row.branch.selected ? ' active':'')" class="tree-grid-row">
219+
<td><a ng-click="user_clicks_branch(row.branch)"><i ng-class="row.tree_icon"
220+
ng-click="row.branch.expanded = !row.branch.expanded"
221+
class="indented tree-icon"></i></a><span class="indented tree-label" ng-click="on_user_click(row.branch)">
222+
{{row.branch[expandingProperty.field] || row.branch[expandingProperty]}}</span>
223+
</td>
224+
<td ng-repeat="col in colDefinitions">
225+
<div ng-if="col.cellTemplate" compile="col.cellTemplate" cell-template-scope="col.cellTemplateScope"></div>
226+
<div ng-if="!col.cellTemplate">{{row.branch[col.field]}}</div>
227+
</td>
228+
</tr>
229+
</tbody>
230+
</table>
231+
</div>
232+
```
233+
135234
### Specifying the template
136235

137236
There are two ways to specify the template of the pagination controls directive:
@@ -168,7 +267,8 @@ Later, execute the query using promises and update the `tree_data` value with th
168267

169268
If for any reason you want to use a custom HTML to show a specific cell, for showing an image, colorpicker,
170269
or something else, you can use the `cellTemplate` option in the `col-defs` array, just use
171-
`{{ row.branch[col.field] }}` as the placeholder for the value of the cell anywhere in the HTML.
270+
`{{ row.branch[col.field] }}` as the placeholder for the value of the cell anywhere in the HTML - use `{{ row.branch[expandingProperty.field] }}`
271+
if providing a template for the expanding property..
172272

173273
Example:
174274

@@ -198,3 +298,9 @@ and then use it in `cellTemplate` as:
198298
and will work as expected.
199299

200300
#### Inspired by [abn tree](https://github.com/nickperkinslondon/angular-bootstrap-nav-tree)
301+
302+
## Release History
303+
Version | Date | Change summary
304+
------|---------|--------------
305+
0.2.0 | May 24 2016 | synchronise NPM and bower releases
306+
0.1.0 | May 13 2016 | initial NPM release

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "angular-bootstrap-grid-tree",
3-
"version": "0.1.0",
4-
"description": "A Grid That display Tree Control for AngularJS, using CSS animation and Bootstrap style",
3+
"version": "0.2.0",
4+
"description": "AngularJS directive for a tree grid, using Bootstrap",
55
"main": [
66
"src/treeGrid.css",
77
"src/tree-grid-directive.js"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-bootstrap-grid-tree",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "AngularJS directive for a tree grid, using Bootstrap",
55
"repository": "https://github.com/khan4019/tree-grid-directive.git",
66
"dependencies": {},

0 commit comments

Comments
 (0)