Getting ID for insertNewChild from DB

This seems like it would be a common question, but so far I haven’t been able to figure it out or find an answer via search.

using dhtmlxTree with connector, I have an “add item” button with an onclick event that should presumably call insertNewChild. According to the documentation, the usage is like so:


I don’t want to specify itemId, I want to (have to) use the autonumber ID that is assigned by the db after insertion. (I’m thinking maybe I can call insertNewChild with a fake itemId and then update the UI with the proper ID…?) dhtmlxConnector can use the get_new_id function in the afterProcessing event, but I’m unsure how I might get this information back to the tree to set/update the newly inserted item in the tree itself.

(I’m thinking maybe I can call insertNewChild with a fake itemId and then update the UI with the proper ID…?

Yes, you may use any id on client, insert an item to the database and return the new id with the response. changeItemId method allow to redefine item id.

There is DataProcessor that sends changes to the server and processes responses automatically.

Please check sample in the connector package:

Ok, thanks for the info… I think I’m getting closer, just not sure how the ID is updated in the example…

Would I be able to use this in the afterProcessing event:
$newID = $action->get_new_id();
and then:
to update the UI? According to the documentation, this should work…

Otherwise it would seem like I would need to use something like this when creating the DP:

myDataProcessor.attachEvent(“onAfterInsert”, function(nodeId, cType, newId) {

…but I’m not sure whether that would even work.

If connector and dataprocessor are used, an item id is updated automatically. You don’t need to use an additional code, like $action->get_new_id() or tree.changeItemId(nodeId,newId);