@@ -10,11 +10,26 @@ Feel free to whatever you want to do with it.
10
10
11
11
### Mininum to start
12
12
--------------------
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
14
29
15
30
<tree-grid tree-data="tree_data"></tree-grid>
16
31
17
- Then include the module as a dependency in your application:
32
+ Include the module as a dependency in your application:
18
33
19
34
angular.module('myApp', ['treeGrid'])
20
35
@@ -109,7 +124,8 @@ Example:
109
124
];
110
125
111
126
** 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).
113
129
114
130
** my_tree:** you can use ` tree-control ` to use expand all and collapse all. Check it out in the link provided for demo.
115
131
@@ -132,6 +148,89 @@ need to redirect if a branch is selected.
132
148
console.log('you clicked on', branch)
133
149
}
134
150
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
+ < ; tr ng-repeat="row in tree_rows | searchFor:$parent.filterString:expandingProperty:colDefinitions:<b >true</b > track by row.branch.uid"> ;
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
+
135
234
### Specifying the template
136
235
137
236
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
168
267
169
268
If for any reason you want to use a custom HTML to show a specific cell, for showing an image, colorpicker,
170
269
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..
172
272
173
273
Example:
174
274
@@ -198,3 +298,9 @@ and then use it in `cellTemplate` as:
198
298
and will work as expected.
199
299
200
300
#### 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
0 commit comments