Skip to content

Commit b7554e6

Browse files
authored
Merge pull request #113 from aboveproperty/sortOptions
Implement sort options and add to docs, correct spacing, closes #96
2 parents d1f5f49 + eed124a commit b7554e6

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Run supported actions on the tree by registering it to your controller with the
3333
typesOptions=typesOptions
3434
searchOptions=searchOptions
3535
searchTerm=searchTerm
36+
sort=sort
3637
contextMenuReportClicked=(action "contextMenuReportClicked")
3738
eventDidBecomeReady=(action "handleTreeDidBecomeReady")
3839
}}
@@ -136,6 +137,7 @@ The following [plugins](http://www.jstree.com/plugins/) are currently supported.
136137
* Checkbox
137138
* Contextmenu
138139
* Search
140+
* Sort
139141
* State
140142
* Types
141143
* Wholerow
@@ -164,6 +166,16 @@ In **Handlebars**:
164166
}}
165167
```
166168

169+
The sort plugin accepts a sort function instead of an options hash.
170+
171+
```Handlebars
172+
{{ember-jstree
173+
[...]
174+
plugins=plugins
175+
sort=sortFunction
176+
}}
177+
```
178+
167179
### Configuring tree refresh
168180

169181
Send in the following [properties](<https://www.jstree.com/api/#/?f=refresh()>) to control how the tree is refreshed when you change the data

addon/components/ember-jstree.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export default Component.extend(InboundActions, EmberJstreeActions, {
3535
typesOptions: null,
3636
searchOptions: null,
3737
dndOptions: null,
38+
sort: null,
3839

3940
selectionDidChange: null,
4041
treeObject: null,
@@ -149,6 +150,11 @@ export default Component.extend(InboundActions, EmberJstreeActions, {
149150
configObject["search"] = searchOptions;
150151
}
151152

153+
let sort = this.get("sort");
154+
if (isPresent(sort) && pluginsArray.includes("sort")) {
155+
configObject["sort"] = sort;
156+
}
157+
152158
let stateOptions = this.get("stateOptions");
153159
if (isPresent(stateOptions) && pluginsArray.includes("state")) {
154160
configObject["state"] = stateOptions;
@@ -456,23 +462,23 @@ export default Component.extend(InboundActions, EmberJstreeActions, {
456462
});
457463

458464
let pluginsArray = this.get("plugins");
459-
460-
if(isPresent(pluginsArray) && pluginsArray.indexOf("search") > -1){
461-
/*
462-
Event: search.jstree
463-
Action: eventDidSearch
464-
triggered when a search action is performed
465-
*/
466-
treeObject.on("search.jstree", (event, data) => {
467-
next(this, function() {
468-
if (this.get("isDestroyed") || this.get("isDestroying")) {
469-
return;
470-
}
471-
this.callAction("eventDidSearch", event, data);
472-
});
465+
466+
if (isPresent(pluginsArray) && pluginsArray.indexOf("search") > -1) {
467+
/*
468+
Event: search.jstree
469+
Action: eventDidSearch
470+
triggered when a search action is performed
471+
*/
472+
treeObject.on("search.jstree", (event, data) => {
473+
next(this, function() {
474+
if (this.get("isDestroyed") || this.get("isDestroying")) {
475+
return;
476+
}
477+
this.callAction("eventDidSearch", event, data);
473478
});
479+
});
474480
}
475-
481+
476482
if (isPresent(pluginsArray) && pluginsArray.indexOf("checkbox") > -1) {
477483
/*
478484
Event: disable_checkbox.jstree

0 commit comments

Comments
 (0)