Hello,
I am new to syncFusion infact I am newbie to ReactJS only. I am using syncfusion's treeview.
My requirement is to load a checkbox tree and pre-check(check initially while loading) few checkboxes. So I am using treeview's checkedNodes property to do this. I get the list of ids of all checkboxes from props. Tree loads fine with all the checkboxes preselected. I am also binding nodeChecked event to print the list of all checked checkeboxes. I use this.treeView.getAllCheckedNodes() function to get the list of checkedNodes.
Now, My problem is that if I check/unchek some or all checkboxes the UI gets updated but this.treeView.getAllCheckedNodes() always returns prechecked checkboxes list only which I assign to checkedNodes while loading the treeview. Why so? I want getAllCheckedNodes()
to return actual checked checkboxes on the treeview. How can I achieve this?
Below is the code snippet.
class FncTree extends Component {
constructor(props) {
super(props);
}
this.state = {
nodes: [],
}
this.fields = {}
getTestTreeSkeleton = () => {
fetch(
"http://xxxxxx.som.url.togetthe.skeletonof.checkboxtree
)
.then(response => response.json())
.then(json => {
this.fields = {
dataSource: json.skeleton,
id: "id",
parentID: "pid",
text: "name",
hasChildren: "hasChild"
};
this.setState({
nodes: json.skeleton
});
});
};
componentDidMount() {
this.getTestTreeSkeleton();
}
nodeChecked = () => {
let checkedNodes = this.treeView.getAllCheckedNodes().sort();
console.log(checkedNodes );
}
createdCall= () => {
let checkedNodes = this.treeView.getAllCheckedNodes().sort();
console.log(checkedNodes );
}
render() {
console.log("this.state.selectedFncs : ", this.state.selectedFncs);
return (
<React.Fragment>
{this.state.nodes.length > 0 ? (
<TreeViewComponent
fields={this.fields}
showCheckBox={true}
created={this.createdCall}
nodeChecked={this.nodeChecked}
checkedNodes={this.props.preSelectedCheckboxes}
ref={treeView => (this.treeView = treeView)}
cssClass="custom-treeview"
/>
) : (
<div className="loader-gif-container">
<img
className="loader-gif"
src={process.env.PUBLIC_URL + "/loaderSmall.gif"}
/>
</div>
)}
</React.Fragment>
);
}
}