diff --git a/README.md b/README.md index cfab056..5c60d2f 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ Run supported actions on the tree by registering it to your controller with the typesOptions=typesOptions searchOptions=searchOptions searchTerm=searchTerm + sort=sort contextMenuReportClicked=(action "contextMenuReportClicked") eventDidBecomeReady=(action "handleTreeDidBecomeReady") }} @@ -136,6 +137,7 @@ The following [plugins](http://www.jstree.com/plugins/) are currently supported. * Checkbox * Contextmenu * Search +* Sort * State * Types * Wholerow @@ -164,6 +166,16 @@ In **Handlebars**: }} ``` +The sort plugin accepts a sort function instead of an options hash. + +```Handlebars +{{ember-jstree + [...] + plugins=plugins + sort=sortFunction +}} +``` + ### Configuring tree refresh Send in the following [properties]() to control how the tree is refreshed when you change the data diff --git a/addon/components/ember-jstree.js b/addon/components/ember-jstree.js index 7a7c97b..43e4cc9 100644 --- a/addon/components/ember-jstree.js +++ b/addon/components/ember-jstree.js @@ -35,6 +35,7 @@ export default Component.extend(InboundActions, EmberJstreeActions, { typesOptions: null, searchOptions: null, dndOptions: null, + sort: null, selectionDidChange: null, treeObject: null, @@ -149,6 +150,11 @@ export default Component.extend(InboundActions, EmberJstreeActions, { configObject["search"] = searchOptions; } + let sort = this.get("sort"); + if (isPresent(sort) && pluginsArray.includes("sort")) { + configObject["sort"] = sort; + } + let stateOptions = this.get("stateOptions"); if (isPresent(stateOptions) && pluginsArray.includes("state")) { configObject["state"] = stateOptions; @@ -456,23 +462,23 @@ export default Component.extend(InboundActions, EmberJstreeActions, { }); let pluginsArray = this.get("plugins"); - - if(isPresent(pluginsArray) && pluginsArray.indexOf("search") > -1){ - /* - Event: search.jstree - Action: eventDidSearch - triggered when a search action is performed - */ - treeObject.on("search.jstree", (event, data) => { - next(this, function() { - if (this.get("isDestroyed") || this.get("isDestroying")) { - return; - } - this.callAction("eventDidSearch", event, data); - }); + + if (isPresent(pluginsArray) && pluginsArray.indexOf("search") > -1) { + /* + Event: search.jstree + Action: eventDidSearch + triggered when a search action is performed + */ + treeObject.on("search.jstree", (event, data) => { + next(this, function() { + if (this.get("isDestroyed") || this.get("isDestroying")) { + return; + } + this.callAction("eventDidSearch", event, data); }); + }); } - + if (isPresent(pluginsArray) && pluginsArray.indexOf("checkbox") > -1) { /* Event: disable_checkbox.jstree