Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Stevo on May 07, 2008 07:43
open dhtmlx forum
[TREE] Get reference for node if dropped as last in tree

Hi :)

I use dropHandler to handle updating my db on reordering nodes of tree

tree_<%=random_id%>.attachEvent("onDrop",dropHandler);

function dropHandler(id_dragged, id_target, id_before, tree_source, tree_target)
{
<%= remote_function :url => {:controller => :lbuilder, :action => :relocate_node}, :with => "'id_parent=' + id_target + '&before_id=' + id_before + '&id=' + id_dragged" %>
}

Everything works fine, as long as I do not drop node as the last none, because I do not get neither id_before nor id_target, so I have no reference for node being droped.

You can say that I can place it as last one in my data set, but what if tree was filtered before reordering? Then I would expect ie. my node being dropped to be placed after node 7 (which is the last one after filter) but it will be placed after node 9 (last one in data set).

Anyway, if I get any reference for node being dropped as last one in tree, it will solve the problem... how can I accomplish that ?

Regards
Stevo
Answer posted by Support on May 07, 2008 09:52
>> I do not get neither id_before nor id_target, so I have no reference for node being droped
If you mean drop on free space of tree - actually they provided
    id_target = 0 - this is default virtual root id value
    id_before = null - because item droped as last one, there is no any-one after it, so this value is null

>>if tree was filtered
The tree doesn't support filtering, probably you mean sorting ?

>>Then I would expect ie. my node being dropped to be placed after node
You can get ID of last node of parent ( after which your node will be inserted as )
    var id_after = tree.getItemIdByIndex(id_target,tree.hasChildren(id_target)-1)



Answer posted by Stevo on May 07, 2008 10:04
>> I do not get neither id_before nor id_target, so I have no reference for node being droped
--If you mean drop on free space of tree - actually they provided
   -- id_target = 0 - this is default virtual root id value
    --id_before = null - because item droped as last one, there is no any-one after it, so this value is null

I meant dropping as right (bottom) sibbling of last node (bottom-most).

>>if tree was filtered
--The tree doesn't support filtering, probably you mean sorting ?

Filtered by filtering dataset/generated xml for tree

>>Then I would expect ie. my node being dropped to be placed after node
--You can get ID of last node of parent ( after which your node will be inserted as )
   -- var id_after = tree.getItemIdByIndex(id_target,tree.hasChildren(id_target)-1)

 I think it would be all right for me just to get the id of last (the bottom one) parent node in tree. I'll try solution You provided.