Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save data to database #382

Closed
pm4698 opened this issue Jun 15, 2020 · 12 comments
Closed

Save data to database #382

pm4698 opened this issue Jun 15, 2020 · 12 comments
Labels
answered question Further information is requested

Comments

@pm4698
Copy link

pm4698 commented Jun 15, 2020

Hello there,

I started using orgchart to see how it works. I used this example/theme:
https://balkangraph.com/OrgChartJS-Demos/CustomTemplateCool.html

What i need is when someone drags/drops elements then data is automatically being saved to a database. I know how to send/save data using ajax but i don't know if there is a ready function/suggested way to loop through all nodes and get information like id and order to save it to an array and use it through ajax.

Thank you in advance

@ZornitsaPesheva
Copy link
Collaborator

You can see here our example for ASP.NET MVC:
https://github.com/BALKANGraph/OrgChartWebApp

@pm4698
Copy link
Author

pm4698 commented Jun 16, 2020

Ok, i use PHP and i am loading data from database and its working like a charm. What i need is when performing drag/drop to drop data through ajax and save the new order into my database.

From your example i saw this:

chart.on('update', function (sender, oldNode, newNode) { $.post("@Url.Action("UpdateNode")", newNode) .done(function () { sender.updateNode(newNode); }); return false; });

Is there a parameter in the orgchart to be something like: chart.on ('dragdrop'......) ? Also, if not using .NET can you provide an example of how to loop all nodes to save data into arrays? like old node array and new node array?

@ZornitsaPesheva
Copy link
Collaborator

hi pm4698,

Drag and drop is triggering the update event, so you ca use it to save your data.

@pm4698
Copy link
Author

pm4698 commented Jun 16, 2020

Thanks for the info. So the on update event holds 3 variables: sender, oldNode, newNode. These variables are global? Can you provide a jQuery/Javascript loop example where we loop through all nodes to get new and old Nodes?

@ZornitsaPesheva
Copy link
Collaborator

When you drag and drop a node, you don't need the all nodes data. You just need the newNode and you have to save the data in the function of this event.

chart.on('update', function (sender, oldNode, newNode) {
          // find the id of the newNode in the database and save the data
        });

@pm4698
Copy link
Author

pm4698 commented Jun 16, 2020

So can you tell me within a line what is what?
Per example:
sender: node's id
oldNode: node's old parent id
newNode: node's new parent id

Thank you in advance

@ZornitsaPesheva
Copy link
Collaborator

Where is this from?

@pm4698
Copy link
Author

pm4698 commented Jun 16, 2020

chart.on('update', function (sender, oldNode, newNode) { // find the id of the newNode in the database and save the data });

The above event has 3 variables:sender, oldNode and newNode. What is each of this 3 variables?for a node which is the sender, which ia the oldNode and which the newNode?

@ZornitsaPesheva
Copy link
Collaborator

ZornitsaPesheva commented Jun 16, 2020

sender is the chart (OrgChart object)
oldNode - the node data before moving (with the old paren id)
newNode - the node data after moving (with the new parent id)

@pm4698
Copy link
Author

pm4698 commented Jun 16, 2020

So sender is lets say object's id, oldNode is object's previous pid and newNode is object's new pid?

@ZornitsaPesheva
Copy link
Collaborator

ZornitsaPesheva commented Jun 16, 2020

No, to understand better , you can do this:

        chart.on('update', function (sender, oldNode, newNode) { 
            console.log(sender);
            console.log(oldNode);
            console.log(newNode);
        });

@pm4698
Copy link
Author

pm4698 commented Jun 17, 2020

Thank you very much for your assistance! I used console.dir to check sender, oldNode and newNode and eventually moving object's id is newNode.id and new parent is newNode.pid. I use these 2 variables to update my database and its working like a charm!

Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants