Design error in dataprocessor

I use the DHTMLX-tree in combination with autoloading. When I insert a new child with insertNewChild() I do have to specify a node id. But I do not want to calculate this id on the client side, as it is the id of the server sided database. So I choose e.g. -1 as the node’s id.

Now I can ignore the sent id in my server script, compute and use the new valid database id X, and return -1 as “inserted”. Now I do have a node in the client’s tree with the id -1, which is inconsistent with the database.

Second option: I return X as inserted - as is the actual id I inserted into the database. But now the dataprocessor seems to be in some kind of infinite loop, it keeps sending the command to insert node “-1” over and over again! I guess it cannot identify the result X as the result of the “insert -1”-command.

The only workaround I can think of is to call “insert -1”, ignore the -1 on server side, insert a valid id instead, return “inserted -1”, and refresh the new node’s parent node of the tree “manually”. But this cannot be the sense of the dataprocessor and the autoupdate!

Actually the dataprocessor was created with such situation in mind.

a) When you creating new element you set any unique ID for it ( -1 is not the best choice, because ID still need to be unique, when you creating few new rows ) , ID on client has not any relation to real DB
b) Dataprocessor send data to server, including ID
c) Server side code ignores incoming ID and created record in DB , real ID calculated
d) Server side code sends data back to clietn


    sid - original ID from client
    tid - the real ID which was assigned after inserting data in DB

e) on client side , dataprocessor check the response and change the @sid ID to the @tid ID, so in result newly created element has the same ID as was assigned on server side.

So you just need to return correct @sid , @tid values - all other will be done automatically

on client side , dataprocessor check the response and change the @sid
ID to the @tid ID, so in result newly created element has the same ID
as was assigned on server side.

No - the new element has the ID “sid”, not “tid”. I have to refresh the tree to see the new ID

Unfortunately I am not able to create the example database from dhtmlxTree\samples\dataprocessor\php:

#1064 - You have an error in your SQL syntax near ‘CURRENT_TIMESTAMP(),

  PRIMARY KEY  (item_id)


So I am not able to recreate the problem with that example - but I just added a onClick-event to my tree, where I alert() the currently clicked (and the previously selected) ID, it is always -1. Here’s what I  send:


and this is the servers response:

<?xml version="1.0" encoding="UTF-8"?>

but the alert() in the onClick-event tells me I clicked node -1

The issue caused by different version of MySQL ( because the same SQL code works fine locally ), basically your can remove default clause, it has not any critical sense.

>>and this is the servers response:
The text of response is not fully correct, it need to be
<?xml version="1.0" encoding="UTF-8"?>

 <action type=“insert” sid="-1" tid=“209”/>

…and once again it’s my fault :slight_smile: I just returned the nativeeditor_status. Funny, that it worked with updated/deleted instead of update/delete
Anyway, thanks a lot

The action@type may contain any value - it allows to create custom server side responses ( which allows to handler server side errors for example), but the behavior with ID changing works only for “insert” type.