I am very new trying to understand the dhtmlx functionalities.
In the scripts of the dhtmlxConnector_v10_php show, how to build a tree in examples.
Unfortunately there is nowhere an example, how I can rewrite a node movement into a MySql database (PHP).
The same with checkboxes in a tree. How can I store a change of a checkbox of a node into the database?
I seached in this forum for an example (which works), but whatever I searched for, I was not successful.
dataprocessor sends “tr_order” property that contains index of the updated item. But it is not processed by dataprocessor. For this reason, you need to set an update handler for connector. Please see docs about custom updates (tr_order will be evailable in event and can be got by get_value method):
checkbox state is not sent to server by DataProcessor. You need to set onCheck event that will set checkbox state in item userdata and mark this item as “updated” for DataProcessor:
tree.attachEvent(“onCheck”,function(id,state){
tree.setUserData(id,“checked”,state); // sets “checked” userdata
dataProcessor.setUpdated(id,true); // marked an item as updated
});
So, an item with changed checkbox state (“checked” property) will be sent to server on dp.sendData() call as well other updated nodes. To save “checked” property in database you may use the same approach as for “tr_order” (see above).
I tried to implement your advices, but I dont know exacly WHERE to implement.
I set the following code before another similar command in file 01p_basic_connector.php (because it connects a database):
function custom_format($item){
$item->set_check_state(1);
}
$tree->event->attach(“beforeRender”,“custom_format”);
The nodes are marked, that works.
But how can I use a SELECT-Command (MySQL)?
In the same form I implemented the before_update() command:
function my_update($data){
global $tree;
$parentid = $data->get_value("parentId");
$id = $data->get_value("taskId");
$tree->sql->query("UPDATE tasks SET parentId='{$parentid}' where taskId={$id}");
$data->success(); //if you have made custom update - mark operation as finished
}
$tree->event->attach("beforeUpdate","my_update");
but that does not work at all.
How cant I get a working example, from which I can learn, what where in which order has to be placed?
And if I can - as a plus - edit the tree entry, this very good tree functionality will be used in a project.