xxxxxxxxxx
import React, { Component } from 'react';
import SortableTree from 'react-sortable-tree';
import 'react-sortable-tree/style.css'; // This only needs to be imported once in your app
export default class SortTree extends Component {
constructor(props) {
super(props);
this.state = {
treeData: [
{ title: 'Comic Books', children: [{ title: 'Amazing Spider-Man' },{ title: 'The Incredible Hulk' },{ title: 'Action Comics' },{ title: 'Batman' },{ title: 'New Avengers' }] },
{ title: 'Historical Fiction', children: [{ title: 'The Help' },{ title: 'All the Light We Cannot See' },{ title: ' The Color Purple' },{ title: ' War and Peace' }] },
],
};
}
render() {
return (
<div style={{ height: 800 }}>
<SortableTree
treeData={this.state.treeData}
onChange={treeData => this.setState({ treeData })}
/>
</div>
);
}
}
xxxxxxxxxx
import React, { Component } from 'react';
import SortableTree, { toggleExpandedForAll } from 'react-sortable-tree';
import { Button, Divider, Input } from 'semantic-ui-react';
import 'react-sortable-tree/style.css';
export default class SortTree extends Component {
constructor(props) {
super(props);
this.state = {
searchString: '',
searchFocusIndex: 0,
treeData: [
{ title: 'Comic Books', children: [{ title: 'Amazing Spider-Man' }, { title: 'The Incredible Hulk' }, { title: 'Action Comics' }, { title: 'Batman' }, { title: 'New Avengers' }] },
{ title: 'Historical Fiction Books', children: [{ title: 'The Help' }, { title: 'All the Light We Cannot See' }, { title: ' The Color Purple' }, { title: ' War and Peace' }] },
],
};
}
expandAndCollapse = (expanded) => {
this.setState({
treeData: toggleExpandedForAll({
treeData: this.state.treeData,
expanded,
}),
});
};
updateTreeData(treeData) {
this.setState({ treeData });
}
render() {
const { searchString, searchFocusIndex, treeData } = this.state;
return (
<div style={{ height: 800 }}>
<div style={{ flex: '0 0 auto', padding: '0 15px' }}>
<h2>React Sortable Tree</h2>
<Divider></Divider>
<Button size='mini' color='blue' onClick={() => { this.expandAndCollapse(true); }}>Expand all</Button>
<Button size='mini' color='blue' onClick={() => { this.expandAndCollapse(false); }}>Collapse all</Button>
<Input size='mini' placeholder='Search' value={searchString}
onChange={event => this.setState({ searchString: event.target.value })}/>
</div>
<Divider></Divider>
<SortableTree
searchQuery={searchString}
onChange={this.updateTreeData}
searchFocusOffset={searchFocusIndex}
treeData={treeData}
onChange={treeData => this.setState({ treeData })}
/>
</div>
);
}
}
xxxxxxxxxx
import React, { Component } from 'react';
import SortableTree, {toggleExpandedForAll} from 'react-sortable-tree';
import { Button, Divider} from 'semantic-ui-react';
import 'react-sortable-tree/style.css'; // This only needs to be imported once in your app
export default class SortTree extends Component {
constructor(props) {
super(props);
this.state = {
treeData: [
{ title: 'Comic Books', children: [{ title: 'Amazing Spider-Man' },{ title: 'The Incredible Hulk' },{ title: 'Action Comics' },{ title: 'Batman' },{ title: 'New Avengers' }] },
{ title: 'Historical Fiction', children: [{ title: 'The Help' },{ title: 'All the Light We Cannot See' },{ title: ' The Color Purple' },{ title: ' War and Peace' }] },
],
};
}
expandAndCollapse = (expanded) => {
this.setState({
treeData: toggleExpandedForAll({
treeData: this.state.treeData,
expanded,
}),
});
};
render() {
return (
<div style={{ height: 800 }}>
<h2>React Sortable Tree</h2>
<Divider></Divider>
<Button size='mini' color='blue' onClick={() => { this.expandAndCollapse(true); }}>Expand all</Button>
<Button size='mini' color='blue' onClick={() => { this.expandAndCollapse(false); }}>Collapse all</Button>
<SortableTree
treeData={this.state.treeData}
onChange={treeData => this.setState({ treeData })}
/>
</div>
);
}
}
xxxxxxxxxx
import React, { Component } from 'react';
import SortableTree, {toggleExpandedForAll} from 'react-sortable-tree';
import { Button, Divider} from 'semantic-ui-react';
import 'react-sortable-tree/style.css'; // This only needs to be imported once in your app
export default class SortTree extends Component {
constructor(props) {
super(props);
this.state = {
treeData: [
{ title: 'Comic Books', children: [{ title: 'Amazing Spider-Man' },{ title: 'The Incredible Hulk' },{ title: 'Action Comics' },{ title: 'Batman' },{ title: 'New Avengers' }] },
{ title: 'Historical Fiction', children: [{ title: 'The Help' },{ title: 'All the Light We Cannot See' },{ title: ' The Color Purple' },{ title: ' War and Peace' }] },
],
};
}
expandAndCollapse = (expanded) => {
this.setState({
treeData: toggleExpandedForAll({
treeData: this.state.treeData,
expanded,
}),
});
};
render() {
return (
<div style={{ height: 800 }}>
<h2>React Sortable Tree</h2>
<Divider></Divider>
<Button size='mini' color='blue' onClick={() => { this.expandAndCollapse(true); }}>Expand all</Button>
<Button size='mini' color='blue' onClick={() => { this.expandAndCollapse(false); }}>Collapse all</Button>
<SortableTree
treeData={this.state.treeData}
onChange={treeData => this.setState({ treeData })}
/>
</div>
);
}
}