Move nodes in Tree, check/uncheck entries with Mysql - How?

Hello,

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.

A simple example would help a lot.

Thank you for any kind of help!!

Best regards!
Pauli

Hello,

both properties are not processed automatically.

  • move nodes

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):

docs.dhtmlx.com/doku.php?id=dhtm … ex_updates

  • check/uncheck

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).

If you are using connector to render tree xml, you will probably need to apply order and checkbox state in it. The following docs will help:
docs.dhtmlx.com/doku.php?id=dhtm … re_loading
docs.dhtmlx.com/doku.php?id=dhtm … heck_state

Hello Alexandra,

thank you for information.

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.

Thank you very much your kindly help in advance!

Best regards.
Paul

Hello,

The nodes are marked, that works.
But how can I use a SELECT-Command (MySQL)?

The checked state should be fetched with other tree data (by render_sql or render_table method):

function custom_format($item){
if($item->get_value(“checked”))
$item->set_check_state(1);
}
$tree->event->attach(“beforeRender”,“custom_format”);

$tree->render_sql(“tasks”,“taskId”,“taskName,checked”,"",“parentId”);

but that does not work at all.

Make sure that you are calling $tree->event->attach(“beforeUpdate”,“my_update”); before render_table method

$tree->event->attach(“beforeUpdate”,“my_update”);
$tree->render_table(“tasks”,“taskId”,“taskName”,"",“parentId”);