Drag / Drop events
Drag-Move events


You can enable DragAndDrop = true and the treeviews will automatically get drag and drop functionality. You can use various events to get the source and destination nodes both on the source and on the destination treeviews both on the client-side with javascript and on the server-side in a Controller, provided you have set the DragAndDropUrl property of the treeview.
@using Trirand.Web.Mvc
@using MVCDemo.Models
@using System.Web.UI.WebControls

<!DOCTYPE html>
<html lang="en-us">
<head>
    <meta charset="utf-8">
    <title>jqTreeView for ASP.NET MVC - Drag And Drop</title>    
    <!-- jQuery runtime minified -->
    <script src="~/Scripts/jquery-3.0.0.min.js" type="text/javascript"></script>
    <!-- The jqTreeView client-side javascript -->
    <script src="~/Scripts/trirand/jquery.jqTreeView.min.js" type="text/javascript"></script>
    <!-- The jQuery UI theme that will be used by the grid. -->
    <link rel="stylesheet" type="text/css" href="http://code.jquery.com/ui/1.11.4/themes/redmond/jquery-ui.css" />
    <!-- The jQuery UI theme extension jqTreeView needs -->
    <link rel="stylesheet" type="text/css" href="~/Content/themes/ui.jqtreeview.css" />
</head>
<body>    
    <table width="1020">
        <tr>
            <td width="310" valign="top">
                @(Html.Trirand().JQTreeView(
                        new JQTreeView
                        {
                            DataUrl = Url.Action("DragAndDrop_TreeView1_DataRequested"),
                            // If DragAndDropUrl is set, an controller action wil be called
                            // with event arguments tha can determine the 
                            // source and destionation nodes and treeviews
                            DragAndDropUrl = Url.Action("DragAndDrop_TreeView1_NodesDropped"),
                            DragAndDrop = true,
                            Height = Unit.Percentage(100),
                            Width = Unit.Pixel(300),
                            MultipleSelect = true,
                            ClientSideEvents = new TreeViewClientSideEvents
                            {
                                NodesDragged = "nodesDragged",
                                NodesMoved = "nodesMoved",   
                                NodesDropped = "nodesDropped",
                            }
                        }, "treeview1"))           
            </td>
            <td width="310" valign="top">
                @(Html.Trirand().JQTreeView(
                        new JQTreeView
                        {
                            DataUrl = Url.Action("DragAndDrop_TreeView2_DataRequested"),                            
                            DragAndDrop = true,                            
                            MultipleSelect = true,
                            Height = Unit.Percentage(100),
                            Width = Unit.Pixel(300),
                            ClientSideEvents = new TreeViewClientSideEvents
                            {
                                NodesDragged = "nodesDragged",
                                NodesMoved = "nodesMoved",
                                NodesDropped = "nodesDropped",
                            }
                        }, "treeview2"))           
            </td>          
            <td width="290" valign="top" style="font-family:Tahoma; font-size:120%;">
                <fieldset>
                    <legend >Drag / Drop events</legend>
                    <div id="dragDropLog" style="height:300px; overflow: auto;"></span>
                </fieldset>
            </td>
            <td width="290" valign="top" style="font-family:Tahoma; font-size:120%;">
                <fieldset title="Drag-Move events">                    
                    <legend>Drag-Move events</legend>                    
                    <div id="moveLog" style="height:300px; overflow: auto;"></span>
                </fieldset>
            </td>        
        </tr>        
    </table>    
    
    <script type="text/javascript">    
    
    function nodesDragged(args, event) {
        // NodesDragged client-side event has the following arguments
        // args.draggedNodes -> array, list of nodes being currently dragged
        // args.sourceTreeView -> an instance to the client-side object of the parent treeview
        // event -> the browser event object
        
        var srcTreeView = args.sourceTreeView; // the instance to the treeview parent                
        
        var draggedNodesText = "";
        for (var i=0; i<args.draggedNodes.length; i++) {
            var draggedNodeOptions = srcTreeView.getNodeOptions(args.draggedNodes[i]); // get node options like Text, Value, etc    
            draggedNodesText = draggedNodesText + draggedNodeOptions.text + ",";
        }           
        
        
        var message = "<b>" + draggedNodesText + "</b>" + 
                      " dragged from " + srcTreeView.options.id;                      
        
        var dragDropLog = $("#dragDropLog");
        dragDropLog.prepend(message);
    };
    
    function nodesMoved(args, event) {
        // NodesMoved client-side event has the following arguments
        // args.movedNodes -> array, list of nodes being currently dragged
        // args.sourceTreeView -> an instance to the client-side object of the parent treeview
        // event -> the browser event object
        
        var draggedNode = args.movedNodes[0]; // no multiple select in this sample, so just one node
        var srcTreeView = args.sourceTreeView; // the instance to the source treeview parent                
        var nodeOptions = srcTreeView.getNodeOptions(draggedNode); // get node options like Text, Value, etc
        
        var message = "Node move: " + nodeOptions.text + "-> X: " +  event.pageX + " Y: " + event.pageY + "<br/>";
        
        var moveLog = $("#moveLog");
        moveLog.prepend(message);
        
    };
    
    
    function nodesDropped(args, event) {
        // NodesDropped client-side event has the following arguments
        // args.draggedNodes -> array, list of nodes being currently dragged
        // args.sourceTreeView -> an instance to the client-side object of the parent treeview
        // args.destinationNode -> the reference to the destination node
        // args.destinationTreeView -> the reference to the destination treeview
        
        var srcTreeView = args.sourceTreeView; // the instance to the treeview parent        
        var destTreeView = args.destinationTreeView; // get the destination treeview
        var destNode = args.destinationNode; // destination node can only be one, no need for array 
        
        var draggedNodesText = "";
        for (var i=0; i<args.draggedNodes.length; i++) {
            var draggedNodeOptions = srcTreeView.getNodeOptions(args.draggedNodes[i]); // get node options like Text, Value, etc    
            draggedNodesText = draggedNodesText + draggedNodeOptions.text + ",";
        }   
        
        var destNodeOptions = destTreeView.getNodeOptions(destNode); // get the options of the destination node
        
        var message = "<b>" + draggedNodesText + "</b>" + 
                      " from " + srcTreeView.options.id + " dropped on " +
                      "<b>" + destNodeOptions.text + "</b>" +
                      " from " + destTreeView.options.id + "<br/>";
        
        var dragDropLog = $("#dragDropLog");
        dragDropLog.prepend(message);

        srcTreeView.postData = new Object();
        srcTreeView.postData.firstName = "John";
        srcTreeView.postData.lastName = "Smith";
    };
    
    </script>
            
    <br />
    <br />
    <div>
          
    </div>
</body>
</html>
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Trirand.Web.Mvc;

namespace MVCDemo.Controllers.Tree
{
    public partial class TreeController : Controller
    {
        public ActionResult DragAndDrop()
        {
            return View();
        }

        public JsonResult DragAndDrop_TreeView1_DataRequested()
        {
            var tree = new JQTreeView();

            List<JQTreeNode> nodes = new List<JQTreeNode>();

            nodes.Add(new DragLeafNode { Text = "Europe" });
            nodes.Add(new DragFolderNode { Text = "North America", Expanded = true });
            nodes.Add(new DragLeafNode { Text = "Australia" });

            var secondNode = nodes.Find(n => n.Text == "North America");

            secondNode.Nodes.Add(new DragLeafNode { Text = "New York" });
            secondNode.Nodes.Add(new DragFolderNode { Text = "California", Expanded = true });
            secondNode.Nodes.Add(new DragLeafNode { Text = "Texas" });

            var california = secondNode.Nodes.Find(n => n.Text == "California");

            california.Nodes.Add(new DragLeafNode { Text = "Los Angeles" });
            california.Nodes.Add(new DragLeafNode { Text = "San Francisco" });
            california.Nodes.Add(new DragLeafNode { Text = "San Diego" });
            california.Nodes.Add(new DragLeafNode { Text = "Sacramento" });

            return tree.DataBind(nodes);
        }

        public class DragAndDropPostData
        {
            string firstName { get; set; }
            string lastName { get; set; }
        }

        public ActionResult DragAndDrop_TreeView1_NodesDropped()
        {
            var tree = new JQTreeView();
            JQTreeNodeDropEventArgs args = tree.GetDragDropInfo();

            // on the server side you can access the source and destionation
            // nodes and treevies and update a database, file system, etc
            List<JQTreeNode> draggedNodes = args.DraggedNodes;
            JQTreeNode destinationNode = args.DestinationNode;
            string destinationTreeViewID = args.DestinationTreeViewID;
            string sourceTreeViewID = args.SourceTreeViewID;

            // use the information and update something here

            return new EmptyResult();
        }

        public JsonResult DragAndDrop_TreeView2_DataRequested()
        {
            var tree = new JQTreeView();

            List<JQTreeNode> nodes = new List<JQTreeNode>();

            nodes.Add(new DragLeafNode { Text = "One" });
            nodes.Add(new DragFolderNode { Text = "Two", Expanded = true });
            nodes.Add(new DragLeafNode { Text = "Three" });

            var secondNode = nodes.Find(n => n.Text == "Two");

            secondNode.Nodes.Add(new DragLeafNode { Text = "2.1" });
            secondNode.Nodes.Add(new DragFolderNode { Text = "2.2", Expanded = true });
            secondNode.Nodes.Add(new DragLeafNode { Text = "2.3" });

            secondNode.Nodes.Find(n => n.Text == "2.2").Nodes.Add(new DragLeafNode { Text = "2.2.1" });
            secondNode.Nodes.Find(n => n.Text == "2.2").Nodes.Add(new DragLeafNode { Text = "2.2.2" });
            secondNode.Nodes.Find(n => n.Text == "2.2").Nodes.Add(new DragLeafNode { Text = "2.2.4" });
            secondNode.Nodes.Find(n => n.Text == "2.2").Nodes.Add(new DragLeafNode { Text = "2.2.3" });

            return tree.DataBind(nodes);
        }

        public class DragFolderNode : JQTreeNode
        {
            public DragFolderNode()
            {
                ImageUrl = "/content/images/folder.png";
                ExpandedImageUrl = "/content/images/folder-open.png";
            }
        }

        public class DragLeafNode : JQTreeNode
        {
            public DragLeafNode()
            {
                ImageUrl = "/content/images/document.png";
            }
        }
        
    }
}
Switch theme:


Theming is based on the very popular jQuery ThemeRoller standard. This is the same theming mechanism used by jQuery UI and is now a de-facto standard for jQuery based components. The benefits of using ThemeRoller are huge. We can offer a big set of ready to use themes created by professional designers, including Windows-like themes (Redmond), Apple-like theme (Cupertino), etc. In addition to that any jQuery UI controls on the same page will pick the same theme.

Last, but not least, you can always roll your own ThemeRoller theme, using the superb Theme Editor

To use a theme, simply reference 2 Css files in your Html <head> section - the ThemeRoller theme you wish to use, and the jqGrid own ThemeRoller Css file. For example (Redmond theme):

<link rel="stylesheet" type="text/css" media="screen" href="/themes/redmond/jquery-ui-1.8.2.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="/themes/ui.jqgrid.css" />