dabeng / react-orgchart

It's a simple and direct organization chart plugin. Anytime you want a tree-like chart, you can turn to OrgChart.
MIT License
131 stars 112 forks source link

Export new datasource #28

Closed Gabbosaur closed 3 years ago

Gabbosaur commented 3 years ago

Hi, is there a way to export the datasource upon adding/deleting/updating the chart? I saw on the jQuery version that there is a method called getHierarchy(), which is what I am looking for. But there is no such method in this react version. Does anyone have any suggestion? Thanks.

DEADushka108 commented 3 years ago

you can use this variant https://github.com/dabeng/react-orgchart/blob/master/src/edit-chart/edit-chart.js . In this example you can use JSONDigger and useState for all manipulations with your ds.

jnachman123 commented 3 years ago

is there anyway to call the orgchart and get the current datasource status. e.g. console.log(orgchart.datasource)

Gabbosaur commented 3 years ago

is there anyway to call the orgchart and get the current datasource status. e.g. console.log(orgchart.datasource)

I managed to do it with this.

  const getHierarchy = async () => {
     const hierarchy = await dsDigger.findNodeById("{ROOT-NODE-ID}");
     console.log(JSON.stringify(hierarchy));
   };

where ROOT-NODE-ID is the id of your root's node. Then you can call the function getHierarchy anywhere you prefer and it prints out the datasource.

jnachman123 commented 3 years ago

@Gabbosaur thanks , forgot to mention that i am using react. and i understand thats not available in that version?

Gabbosaur commented 3 years ago

@Gabbosaur thanks , forgot to mention that i am using react. and i understand thats not available in that version?

That's right. You can use the function I previously posted to get the datasource, and yes I also have used React. Hope that helps!