This is a migrated thread and some comments may be shown as answers.

Move Node in HierarchicalDataSource

2 Answers 44 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
CHRISTOPHER
Top achievements
Rank 1
CHRISTOPHER asked on 15 Jun 2020, 02:37 PM

I have a TreeView implementation that often contains hierarchies that have large numbers of nodes in very flat structures.  While I have drag and drop working, the usability just isn't very good.  So, I'm implementing a cut/paste mechanism where the cut simply remembers the unique id of the source node and on paste of the target node, I get the source node using its id and attempt to .append(sourceNode, targetNode).

However, this doesn't seem to work.

Is this the best way to approach this or is there a different way I should approach this?

 

  $("#mnuHierarchyRightClick").kendoContextMenu({
            target: "#tvHierarchy",
            filter: ".k-in",
            select: function (e) 
            { 
                switch (e.item.id) 
                {
                    case "mnuHierarchyRightClickCut":

                         var tv = $("#tvHierarchy").data("kendoTreeView");
                         var dataItem =  tv.dataItem(e.target);
                    
                        self.setClipBoard(dataItem.ID,'Clipboard: ' + dataItem.Text);

                        break;

                    case "mnuHierarchyRightClickPaste":

                         
                        self.paste(e.target);

                        break;
                    default:
                        break;
                };
            }
        });

// called from click on context menu of the TreeView

MyController.prototype.paste = function (targetNode)
{
    var self = this;

    try
    {
       
        var tv = $("#tvHierarchy").data("kendoTreeView");

        if (targetNode == null) { return false; }

        var targetDataItem = tv.dataItem(targetNode);
        var pastedDataItem = tv.dataSource.get(self.ClipBoardPrimaryKeyID);

        self.setClipBoard(0,'');

        var pastedNode = tv.findByUid(pastedDataItem.uid);

        pastedDataItem.set('parentID', targetDataItem.id);
 
        tv.append(pastedNode,targetNode);

 
    }
    catch(e)
    {
        alert(e);
    }
 
}

2 Answers, 1 is accepted

Sort by
0
CHRISTOPHER
Top achievements
Rank 1
answered on 15 Jun 2020, 07:42 PM

I figured this out.  I could not use the targetNode passed in by the context menu.  I had to go get it again using the targetDataItem.

var targetDataItem = tv.dataItem(targetNode);

var targetNode = tv.findByUid(targetDataItem.uid);

Not sure why but this works.

0
Petar
Telerik team
answered on 17 Jun 2020, 09:00 AM

Hi Christopher,

Thank you for sharing the solution with the community! Your reply will surely help someone who faces the same issue in the future. 

Regards,
Petar
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
TreeView
Asked by
CHRISTOPHER
Top achievements
Rank 1
Answers by
CHRISTOPHER
Top achievements
Rank 1
Petar
Telerik team
Share this question
or