Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#16516 closed defect (invalid)

Tree: items lost using DnD to reorder a node's children

Reported by: AlexG Owned by: bill
Priority: high Milestone: 1.9
Component: Dijit Version: 1.8.0
Keywords: Cc:
Blocked By: Blocking:

Description

http://dojo-toolkit.33424.n3.nabble.com/dijit-Tree-DND-betweenThreshold-bug-please-help-td3992612.html

When dragging in a Tree item 1 before item 2, item 1 disappears somewhere, the same happens when dragging item 1 after item 2.

Attachments (4)

dojo-bug-dijit-Tree-DND.html (2.7 KB) - added by AlexG 7 years ago.
html file
tree-problem-1.png (1.9 KB) - added by AlexG 7 years ago.
step 1
tree-problem-2.png (5.7 KB) - added by AlexG 7 years ago.
step 2
tree-problem-3.png (2.0 KB) - added by AlexG 7 years ago.
step 3

Download all attachments as: .zip

Change History (11)

comment:1 Changed 7 years ago by bill

Owner: changed from bill to AlexG
Status: newpending

Please attach a test case using the "attach file" button. It should be as small as possible to still reproduce the problem, almost always a single HTML file that we can load in the browser (i.e. not PHP, JSP, etc.)

Then, give exact instructions on how to reproduce the problem using your attached test file.

The test case is necessary both to confirm that there's a bug, and for us to be able to debug the problem.

Thanks!

Changed 7 years ago by AlexG

html file

comment:2 Changed 7 years ago by AlexG

Status: pendingnew

Attachment (dojo-bug-dijit-Tree-DND.html) added by ticket reporter.

Changed 7 years ago by AlexG

Attachment: tree-problem-1.png added

step 1

Changed 7 years ago by AlexG

Attachment: tree-problem-2.png added

step 2

Changed 7 years ago by AlexG

Attachment: tree-problem-3.png added

step 3

comment:3 Changed 7 years ago by AlexG

Attached html file and three images that illustrates bug reproduce. Steps to reproduce:

  1. Start drag item 1 before or after item 2 (not over, a successor will be created in this case).
  2. Drop item 1.
  3. Item 1 disappears.
Last edited 7 years ago by AlexG (previous) (diff)

comment:4 Changed 7 years ago by bill

Milestone: tbd1.9
Priority: undecidedhigh
Summary: dijit.Tree DND betweenThresholdTree: items lost while dragging

comment:5 Changed 6 years ago by bill

Owner: changed from AlexG to bill
Status: newassigned

comment:6 Changed 6 years ago by bill

Resolution: invalid
Status: assignedclosed
Summary: Tree: items lost while draggingTree: items lost using DnD to reorder a node's children

I think this is a user error. You've turned on drop-between capability in the tree by setting

betweenThreshold: 5

but your store.put() method doesn't support the "before" parameter to specify ordering of items.

More detail:

dijit/tree/ObjectStoreModel:pasteItem() works by first removing the item being DnD'd:

var oldParentChildren = [].concat(this.childrenCache[this.getIdentity(oldParentItem)]), // concat to make copy
        index = array.indexOf(oldParentChildren, childItem);
oldParentChildren.splice(index, 1);
this.onChildrenChange(oldParentItem, oldParentChildren);

and then adding it back into the right position, using the "before" parameter:

return this.store.put(childItem, {
        overwrite: true,
        parent: newParentItem,
        before: before
});

dijit/tree/ObjectStoreModel:getChildren() sets up a listener for changes to children, in this case changes to the root child's children:

if(res.observe){
        res.observe(lang.hitch(this, function(obj, removedFrom, insertedInto){
                //console.log("observe on children of ", id, ": ", obj, removedFrom, insertedInto);

                // If removedFrom == insertedInto, this call indicates that the item has changed.
                // Even if removedFrom != insertedInto, the item may have changed.
                this.onChange(obj);

                if(removedFrom != insertedInto){
                        // Indicates an item was added, removed, or re-parented.  The children[] array (returned from
                        // res.then(...)) has already been updated (like a live collection), so just use it.
                        when(res, lang.hitch(this, "onChildrenChange", parentItem));
                }
        }), true);      // true means to notify on item changes
}

Unfortunately removedFrom == insertedInto == the old index of the child, so onChildrenChange() isn't called.

It's unfortunate "parent" and "before" support aren't built in to dojo/store/Memory, and that we don't ship a similar store that supports these features, but anyway if you have a custom store that supports "before" (in addition to "parent") then I think this will work.

comment:7 Changed 6 years ago by bill

See #15660 and #15661.

Note: See TracTickets for help on using tickets.