Skip to content

Commit 491f7e5

Browse files
add in sort arg
1 parent d3af825 commit 491f7e5

File tree

5 files changed

+1155
-1279
lines changed

5 files changed

+1155
-1279
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ See the [example CSS](example/tree-view.css) for how this works.
123123

124124
## `<TreeMenu/>` Props
125125

126+
### `sort={<Boolean> || <Function>}`
127+
128+
* If sort is a `Boolean` and true (i.e. `<TreeMenu sort ... />`), the node label will be used for sorting.
129+
* If sort is a `Function`, it will be used as the sort function, with the argument the `React` element (props are available for sorting). Example:
130+
131+
```
132+
<TreeMenu sort={(node) => node.props.value} ... />
133+
```
134+
135+
126136
### `stateful={<Boolean>}`
127137

128138
If you need it, you can make `<TreeMenu/`> keep track of its own state. That being said, `react-tree-menu` was designed to

example/App.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ var App = React.createClass({
349349

350350
return (
351351
<TreeMenu
352+
sort
352353
identifier="id"
353354
onTreeNodeClick={this._setLastActionState.bind(this, "clicked", "2")}
354355
onTreeNodeCollapseChange={this._handleDeclarativeTreeNodePropChange.bind(this, "collapsed")}
@@ -358,8 +359,8 @@ var App = React.createClass({
358359
collapseIconClass="fa fa-chevron-down">
359360
<TreeNode label="Option 1" id="option_1"/>
360361
<TreeNode label="Option 2" id="option_2">
361-
<TreeNode label="Option A" checkbox={true} checked={this.state.staticTreeData["option_2.a"].checked} id="option_2.a"/>
362362
<TreeNode label="Option B" checkbox={true} checked={this.state.staticTreeData["option_2.b"].checked} id="option_2.b"/>
363+
<TreeNode label="Option A" checkbox={true} checked={this.state.staticTreeData["option_2.a"].checked} id="option_2.a"/>
363364
</TreeNode>
364365
<TreeNode label="Option 3" id="option_3"/>
365366
<TreeNode label="Option 4" id="option_4"/>

0 commit comments

Comments
 (0)