|
1 | 1 | # angular-tree-dnd |
| 2 | +[Angular 1.x] Display treeDnD & event DrapnDrop, field 'td' by tree. |
| 3 | + |
| 4 | +##License: |
| 5 | +[](https://github.com/thienhung1989/angular-tree-dnd/blob/master/LICENSE) |
2 | 6 |
|
3 | | -[](https://gitter.im/thienhung1989/angular-tree-dnd?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
4 | | -[Angular 1.x] Display tree dnd & event DrapnDrop, field 'td' by tree (other normal) - without jQuery. |
5 | 7 | ## Current Version |
6 | | -[](http://badge.fury.io/gh/thienhung1989%2Fangular-tree-dnd) |
| 8 | +[](http://badge.fury.io/gh/thienhung1989%2Fangular-tree-dnd) [](https://travis-ci.org/thienhung1989/angular-tree-dnd) |
7 | 9 |
|
| 10 | +## Support *(just when I'm online)* |
8 | 11 | [](https://gitter.im/thienhung1989/ng-tree-dnd?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) |
| 12 | + |
9 | 13 | ## Demo: |
10 | 14 | - http://thienhung1989.github.io/angular-tree-dnd/demo |
11 | 15 | - http://plnkr.co/edit/6zQNvW?p=preview |
12 | 16 |
|
13 | | - |
| 17 | +##Requirement: |
| 18 | +``` |
| 19 | +angular: >=1.2.1 |
| 20 | +``` |
| 21 | + |
14 | 22 | ## Install bower: |
| 23 | +* Bower |
| 24 | +```js |
| 25 | +bower install angular-tree-dnd |
| 26 | +``` |
| 27 | + |
| 28 | +* NPM |
15 | 29 | ```js |
16 | | -bower angular-tree-dnd install |
| 30 | +npm install angular-tree-dnd |
17 | 31 | ``` |
18 | 32 |
|
19 | 33 | * Function 'filter' & 'group by' not add in ng-repeate (it's slow & incompatible with $id($$hash) ) |
@@ -105,67 +119,65 @@ $scope.$callbacks = { |
105 | 119 | * Example |
106 | 120 | **init: |
107 | 121 | ```html |
108 | | - <tree-dnd |
109 | | - class="dnd" |
110 | | - tree-data="tree_data" |
111 | | - tree-control="my_tree" |
112 | | - callbacks="callbacks" |
113 | | - drag-enabled="true" |
114 | | - icon-leaf="none" |
115 | | - icon-expand="fa fa-fw fa-angle-right" |
116 | | - icon-collapse="fa fa-fw fa-angle-down" |
117 | | - template-url="tree-dnd-template.html" |
118 | | - column-defs="col_defs" |
119 | | - expand-on="expanding_property" |
120 | | - on-select="my_tree_handler(node)" |
121 | | - on-click="my_tree_handler(node)" |
122 | | - data-indent="30" |
123 | | - data-indent-unit="px" |
124 | | - data-indent-plus="15" |
125 | | - > |
| 122 | +<tree-dnd |
| 123 | + tree-class="dnd" |
| 124 | + tree-data="tree_data" |
| 125 | + tree-control="my_tree" |
| 126 | + callbacks="callbacks" |
| 127 | + drag-enabled="true" |
| 128 | + icon-leaf="none" |
| 129 | + icon-expand="fa fa-fw fa-angle-right" |
| 130 | + icon-collapse="fa fa-fw fa-angle-down" |
| 131 | + template-url="tree-dnd-template.html" |
| 132 | + column-defs="col_defs" |
| 133 | + expand-on="expanding_property" |
| 134 | + on-select="my_tree_handler(node)" |
| 135 | + on-click="my_tree_handler(node)" |
| 136 | + data-indent="30" |
| 137 | + data-indent-unit="px" |
| 138 | + data-indent-plus="15" |
| 139 | +> |
126 | 140 | </tree-dnd> |
127 | 141 | ``` |
128 | 142 | ** Template Extened: |
129 | 143 | ```html |
130 | 144 | <script type="text/ng-template" id="tree-dnd-template.html"> |
131 | 145 | <div class="tree-dnd"> |
132 | | - <dnd class="dnd"> |
133 | | - <thead> |
134 | | - <tr> |
135 | | - <th ng-class="expandingProperty.titleClass" ng-style="expandingProperty.titleStyle"> |
136 | | - {{expandingProperty.displayName || expandingProperty.field || expandingProperty}} |
137 | | - </th> |
138 | | - <th ng-repeat="col in colDefinitions" ng-class="col.titleClass" |
139 | | - ng-style="col.titleStyle"> |
140 | | - {{col.displayName || col.field}} |
141 | | - </th> |
142 | | - </tr> |
143 | | - </thead> |
144 | | - <tbody> |
145 | | - <tr tree-dnd-node ng-repeat="node in tree_rows track by hashedTree(node)" |
146 | | - ng-show="node.__visible__" ng-class="(node.__selected__ ? ' active':'')" |
147 | | - class="ng-animate "> |
148 | | - <td ng-if="!expandingProperty.template" |
149 | | - ng-style="expandingProperty.cellStyle ? expandingProperty.cellStyle : {'padding-left': $callbacks.calsIndent(node.__level__)}" |
150 | | - ng-click="user_clicks_node(node)" ng-class="expandingProperty.cellClass" |
151 | | - compile="expandingProperty.cellTemplate"> |
152 | | - <span tree-dnd-node-handle> |
153 | | - <i class="fa fa-sort text-muted m-r-sm"></i> |
154 | | - </span> {{node[expandingProperty.field] || node[expandingProperty]}} <a> <i |
155 | | - ng-class="node.__tree_icon__" ng-click="node.__expanded__ = !node.__expanded__" |
156 | | - class="tree-icon"></i> </a> |
157 | | - </td> |
158 | | - <td ng-if="expandingProperty.template" compile="expandingProperty.template"></td> |
159 | | - <td ng-repeat="col in colDefinitions" ng-class="col.cellClass" ng-style="col.cellStyle" |
160 | | - compile="col.cellTemplate"> |
161 | | - {{node[col.field]}} |
162 | | - </td> |
163 | | - </tr> |
164 | | - </tbody> |
165 | | - </dnd> |
166 | | - </div> |
167 | | - <pre>{{ treeData | json }}</pre> |
168 | | - <pre>{{ tree_rows | json }}</pre> |
| 146 | + <dnd class="dnd"> |
| 147 | + <thead> |
| 148 | + <tr> |
| 149 | + <th ng-class="expandingProperty.titleClass" ng-style="expandingProperty.titleStyle"> |
| 150 | + {{expandingProperty.displayName || expandingProperty.field || expandingProperty}} |
| 151 | + </th> |
| 152 | + <th ng-repeat="col in colDefinitions" ng-class="col.titleClass" |
| 153 | + ng-style="col.titleStyle"> |
| 154 | + {{col.displayName || col.field}} |
| 155 | + </th> |
| 156 | + </tr> |
| 157 | + </thead> |
| 158 | + <tbody> |
| 159 | + <tr tree-dnd-node ng-repeat="node in tree_rows track by hashedTree(node)" |
| 160 | + ng-show="node.__visible__" ng-class="(node.__selected__ ? ' active':'')" |
| 161 | + class="ng-animate "> |
| 162 | + <td ng-if="!expandingProperty.template" |
| 163 | + ng-style="expandingProperty.cellStyle ? expandingProperty.cellStyle : {'padding-left': $callbacks.calsIndent(node.__level__)}" |
| 164 | + ng-click="user_clicks_node(node)" ng-class="expandingProperty.cellClass" |
| 165 | + compile="expandingProperty.cellTemplate"> |
| 166 | + <span tree-dnd-node-handle> |
| 167 | + <i class="fa fa-sort text-muted m-r-sm"></i> |
| 168 | + </span> {{node[expandingProperty.field] || node[expandingProperty]}} <a> <i |
| 169 | + ng-class="node.__tree_icon__" ng-click="node.__expanded__ = !node.__expanded__" |
| 170 | + class="tree-icon"></i> </a> |
| 171 | + </td> |
| 172 | + <td ng-if="expandingProperty.template" compile="expandingProperty.template"></td> |
| 173 | + <td ng-repeat="col in colDefinitions" ng-class="col.cellClass" ng-style="col.cellStyle" |
| 174 | + compile="col.cellTemplate"> |
| 175 | + {{node[col.field]}} |
| 176 | + </td> |
| 177 | + </tr> |
| 178 | + </tbody> |
| 179 | + </dnd> |
| 180 | + </div> |
169 | 181 | </script> |
170 | 182 | ``` |
171 | 183 | ## dragStop: |
@@ -217,63 +229,64 @@ $scope.$callbacks = { |
217 | 229 |
|
218 | 230 | * Add 'data' to TreeDnDNode `tree-dnd-node=data` in template; |
219 | 231 | ```html |
220 | | -<tr tree-dnd-node="node" ng-repeat="node in tree_rows track by hashedTree(node)" |
221 | | - ng-show="node.__visible__" ng-class="(node.__selected__ ? ' active':'')" class="ng-animate "> |
| 232 | +<tr tree-dnd-node="node" |
| 233 | + ng-repeat="node in tree_rows track by hashedTree(node)" |
| 234 | + ng-show="node.__visible__" |
| 235 | + ng-class="(node.__selected__ ? ' active':'')" |
| 236 | +> |
222 | 237 | .... |
223 | 238 | </tr> |
224 | 239 | ``` |
225 | 240 |
|
226 | | -# Display ListTree (UL, OL) |
227 | | - |
| 241 | +## Display ListTree (UL, OL) |
228 | 242 | * Combinding with list-tree. |
229 | | - |
230 | 243 | ```html |
231 | | - <script type="text/ng-template" id="tree-dnd-template-render.html"> |
232 | | - <ul tree-dnd-nodes="tree_data"> |
233 | | - <li tree-dnd-node="node" ng-repeat="node in nodes track by node.__hashKey__" |
234 | | - ng-show="node.__visible__" compile="expandingProperty.cellTemplate" |
235 | | - ng-include="'tree-dnd-template-fetch.html'"></li> |
236 | | - </ul> |
237 | | - </script> |
238 | | - |
239 | | - <script type="text/ng-template" id="tree-dnd-template-fetch.html"> |
240 | | - <div class="list-group-item" |
241 | | - ng-class="(node.__selected__ ? 'list-group-item-success':'')" |
242 | | - ng-click="onClick(node)" |
243 | | - ng-style="expandingProperty.cellStyle ? expandingProperty.cellStyle : {}"> |
| 244 | +<script type="text/ng-template" id="tree-dnd-template-render.html"> |
| 245 | + <ul tree-dnd-nodes="tree_data"> |
| 246 | + <li tree-dnd-node="node" ng-repeat="node in nodes track by node.__hashKey__" |
| 247 | + ng-show="node.__visible__" compile="expandingProperty.cellTemplate" |
| 248 | + ng-include="'tree-dnd-template-fetch.html'"></li> |
| 249 | + </ul> |
| 250 | +</script> |
| 251 | + |
| 252 | +<script type="text/ng-template" id="tree-dnd-template-fetch.html"> |
| 253 | + <div class="list-group-item" |
| 254 | + ng-class="(node.__selected__ ? 'list-group-item-success':'')" |
| 255 | + ng-click="onClick(node)" |
| 256 | + ng-style="expandingProperty.cellStyle ? expandingProperty.cellStyle : {}"> |
| 257 | + |
| 258 | + <a class="btn btn-default" aria-label="Justify" type="button" tree-dnd-node-handle> |
| 259 | + <span class="glyphicon glyphicon-align-justify" aria-hidden="true"></span> |
| 260 | + </a> |
| 261 | + |
| 262 | + {{node[expandingProperty.field] || node[expandingProperty]}} |
| 263 | + |
| 264 | + <span ng-class="$iconClass" ng-click="toggleExpand(node)"></span> |
| 265 | + <div class="pull-right"> |
| 266 | + <span ng-repeat="col in colDefinitions" ng-class="col.cellClass" ng-style="col.cellStyle" |
| 267 | + compile="col.cellTemplate"> |
| 268 | + {{node[col.field]}} |
| 269 | + </span> |
| 270 | + </div> |
| 271 | + </div> |
| 272 | + <ul tree-dnd-nodes="node.__children__"> |
| 273 | + <li tree-dnd-node="node" ng-repeat="node in nodes track by node.__hashKey__" |
| 274 | + ng-show="node.__visible__" compile="expandingProperty.cellTemplate" |
| 275 | + ng-include="'tree-dnd-template-fetch.html'"></li> |
| 276 | + </ul> |
| 277 | +</script> |
244 | 278 |
|
245 | | - <a class="btn btn-default" aria-label="Justify" type="button" tree-dnd-node-handle> |
246 | | - <span class="glyphicon glyphicon-align-justify" aria-hidden="true"></span> |
247 | | - </a> |
248 | | - |
249 | | - {{node[expandingProperty.field] || node[expandingProperty]}} |
250 | | - |
251 | | - <span ng-class="$iconClass" ng-click="toggleExpand(node)"></span> |
252 | | - <div class="pull-right"> |
253 | | - <span ng-repeat="col in colDefinitions" ng-class="col.cellClass" ng-style="col.cellStyle" |
254 | | - compile="col.cellTemplate"> |
255 | | - {{node[col.field]}} |
256 | | - </span> |
257 | | - </div> |
258 | | - </div> |
259 | | - <ul tree-dnd-nodes="node.__children__"> |
260 | | - <li tree-dnd-node="node" ng-repeat="node in nodes track by node.__hashKey__" |
261 | | - ng-show="node.__visible__" compile="expandingProperty.cellTemplate" |
262 | | - ng-include="'tree-dnd-template-fetch.html'"></li> |
263 | | - </ul> |
264 | | - </script> |
265 | | - |
266 | | - <tree-dnd tree-data="tree_data" |
267 | | - tree-control="my_tree" |
268 | | - column-defs="col_defs_min" |
269 | | - expand-on="expanding_property" |
270 | | - on-select="select_handler(node)" |
271 | | - on-click="click_handler(node)" |
272 | | - template-url="tree-dnd-template-render.html" |
273 | | - icon-leaf="none" |
274 | | - icon-expand="glyphicon glyphicon-chevron-down" |
275 | | - icon-collapse="glyphicon glyphicon-chevron-right" |
276 | | - ></tree-dnd> |
| 279 | +<tree-dnd tree-data="tree_data" |
| 280 | + tree-control="my_tree" |
| 281 | + column-defs="col_defs_min" |
| 282 | + expand-on="expanding_property" |
| 283 | + on-select="select_handler(node)" |
| 284 | + on-click="click_handler(node)" |
| 285 | + template-url="tree-dnd-template-render.html" |
| 286 | + icon-leaf="none" |
| 287 | + icon-expand="glyphicon glyphicon-chevron-down" |
| 288 | + icon-collapse="glyphicon glyphicon-chevron-right" |
| 289 | +></tree-dnd> |
277 | 290 | ``` |
278 | 291 |
|
279 | 292 |
|
@@ -309,6 +322,7 @@ $scope.$callbacks = { |
309 | 322 | * 'template-copy': to add url template of `Status Copy` *(can bypass string or variable in controller, but just only get $templateCache, if not exist will get default)*; |
310 | 323 | * 'template-move': to add url template of `Status Move` *(can bypass string or variable in controller, but just only get $templateCache, if not exist will get default)*; |
311 | 324 | * Example: |
| 325 | + |
312 | 326 | ```html |
313 | 327 | <tree-dnd class="tree-dnd dnd dnd-hover b-b b-light" tree-data="tree_data" tree-control="my_tree" |
314 | 328 | primary-key="primaryKey" |
@@ -341,5 +355,4 @@ $scope.$callbacks = { |
341 | 355 | ``` |
342 | 356 |
|
343 | 357 | ## Thank To: |
344 | | - |
345 | 358 | This product is the combination and optimization of 2: [](https://github.com/angular-ui-tree/angular-ui-tree) (Drag2Drop) và [](https://github.com/khan4019/tree-grid-directive) (Display Tree2Table). |
0 commit comments