Skip to content

Commit

Permalink
Merge pull request #113 from aboveproperty/sortOptions
Browse files Browse the repository at this point in the history
Implement sort options and add to docs, correct spacing, closes #96
  • Loading branch information
ritesh83 authored May 20, 2021
2 parents d1f5f49 + eed124a commit b7554e6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}}
Expand Down Expand Up @@ -136,6 +137,7 @@ The following [plugins](http://www.jstree.com/plugins/) are currently supported.
* Checkbox
* Contextmenu
* Search
* Sort
* State
* Types
* Wholerow
Expand Down Expand Up @@ -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](<https://www.jstree.com/api/#/?f=refresh()>) to control how the tree is refreshed when you change the data
Expand Down
36 changes: 21 additions & 15 deletions addon/components/ember-jstree.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default Component.extend(InboundActions, EmberJstreeActions, {
typesOptions: null,
searchOptions: null,
dndOptions: null,
sort: null,

selectionDidChange: null,
treeObject: null,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b7554e6

Please sign in to comment.