Version

Configuring the Drag-and-Drop Mode (igTree)

Topic Overview

Purpose

This topic explains, with code examples, how to configure the Drag-and-Drop mode of the igTree™ control, in both JavaScript and MVC.

Required background

The following topics are prerequisites to understanding this topic:

In this topic

This topic contains the following sections:

Drag-and-Drop Mode Configuration Summary

Overview

The Drag-and-Drop mode of the igTree control is managed from the dragAndDropMode property. For the specific settings, see the Drag-and-Drop mode configuration summary chart. Full configuration procedures are provided in the blocks following the chart.

Drag-and-Drop mode configuration summary chart

The following table maps the Drag-and-Drop modes to the property settings that configure them.

In order to: Set the dragAndDropMode property to:
Allow the user to switch between coping and moving using the Ctrl key. default
This is the default setting for the Drag-and-Drop mode, so you only need to have the Drag-and-Drop feature enabled.
Configure the drag-and-drop move to perform copy action only… copy
Configure the drag-and-drop move to perform move action only… move

Code Examples Summary

Code examples summary chart

The following table lists the code examples included in this topic.

Example Description
Code Example: Configuring the Drag-and-Drop Mode in JavaScript This procedure initializes an instance of the igTree with the Drag-and-Drop feature enabled and set to Copy mode, and binds this instance to an XML file.
Code Example: Configuring Drag-and-Drop Mode in MVC This procedure initializes igTree with Drag-and-Drop feature and Copy mode enabled and binds it to an XML file.

Code Example: Configuring the Drag-and-Drop Mode in JavaScript

Introduction

This procedure initializes an instance of the igTree with the Drag-and-Drop feature enabled and set to Copy mode, and binds this instance to a JSON data source.

If you want to set some other mode (Move or Default), in the code snippet under step 3.2., replace the following code: dragAndDropMode: 'copy'

with dragAndDropMode: 'move' or dragAndDropMode: 'default'.

Preview

The following screenshot demonstrates copying of a node as a result of the settings in this procedure.

Overview

This topic takes you step-by-step toward configuring igTree with Drag-and-Drop feature and Copy mode enabled in JavaScript. The following is a conceptual overview of the process:

  1. Defining igTree data source

  2. Adding the script references using Infragistics loader

  3. Configuring the Drag-and-Drop mode to Copy

Steps

The following steps demonstrate how to configure an igTree control instance with Copy Drag-and-Drop mode in JavaScript.

  1. Define igTree data source

For the sake of this example, a simple folder and file structure is created in JSON format. Each object has the following properies

  • Text – the name of the node
  • Value – the type of node - file or folder
  • ImageUrl – URL link which points to a specific node image
  • Folder – array of objects with same data as above

In JavaScript:

[{
      Text: "My Documents",
      Value: "Folder",
      ImageUrl: "../content/images/DocumentsFolder.png",
      Folder: [{
            Text: "2009",
            Value: "Folder",
            ImageUrl: "../content/images/DocumentsFolder.png",
            Folder: [{
                  Text: "Month Report",
                  Value: "File",
                  ImageUrl: "../content/images/Documents.png",
                  Folder: ""
            }, {
                  Text: "Year Report",
                  Value: "File",
                  ImageUrl: "../content/images/Documents.png",
                  Folder: ""
            }]
      }, {
            Text: "2010",
            Value: "Folder",
            ImageUrl: "../content/images/DocumentsFolder.png",
            Folder: [{
                  Text: "Month Report",
                  Value: "File",
                  ImageUrl: "../content/images/Documents.png",
                  Folder: ""
            }, {
                  Text: "Year Report",
                  Value: "File",
                  ImageUrl: "../content/images/Documents.png",
                  Folder: ""
            }]
      }]
}]
  1. Add the script references using Infragistics loader.

    The references are required for initializing the igTree control.

    Create an HTML file (e.g. tree.html) with the following references to in it.

    In HTML:

     <script src="../scripts/jquery.min.js"></script>
     <script src="../scripts/jquery-ui.min.js"></script>
     <script src="../js/infragistics.loader.js"></script>
      $.ig.loader({
                 scriptPath: "../js/",
                 cssPath: "../css/",
                 resources: "igTree"
     });
    
  2. Configure the Drag-and-Drop mode to Copy.

    1. Define the DOM (Document Object Model) Html element placeholder in the tree.html file.

      In HTML:

       <!--igTree target element-->
       <div id="tree">
       </div>
      
    2. Instantiate an igTree with the Drag-and-Drop feature enabled in Copy mode in JavaScript.

      In JavaScript:

       <script>
               $.ig.loader(function () {
                   $("#tree").igTree({
                       checkboxMode: 'triState',
                       singleBranchExpand: true,
                       dataSource: data,
                       dataSourceType: 'json',
                       initialExpandDepth: 0,
                       pathSeparator: '.',
                       bindings: {
                           textKey: 'Text',
                           valueKey: 'Value',
                           imageUrlKey: 'ImageUrl',
                           childDataProperty: 'Folder'
                       },
                       dragAndDrop: true,             
                           dragAndDropSettings: {
                           dragAndDropMode: 'copy'
                       }
                   });
               });        
       </script>
      

Code Example: Configuring Drag-and-Drop Mode in MVC

Introduction

This procedure initializes igTree with Drag-and-Drop feature and Copy mode enabled and binds it to an XML file.

If you want to set some other mode (Move or Default), in the code snippet in step 2., replace the following code (located after the // Configuring Drag-and-drop copy mode comment): settings.DragAndDropMode(DragAndDropMode.Copy);with settings.DragAndDropMode(DragAndDropMode.Move); or settings.DragAndDropMode(DragAndDropMode.Default);.

Preview

The following screenshot is a preview of the final result.

Requirements

To complete the procedure, you need the following:

  • Microsoft® Visual Studio 2010 or newer installed
  • MVC 3 Framework installed
  • Infragistics.Web.Mvc.dll added

Overview

This topic takes you step-by-step toward configuring igTree with Drag-and-Drop feature and Copy mode enabled in MVC. The following is a conceptual overview of the process:

  1. Creating an XML data source file

  2. Defining the View

  3. Defining the Controller

Steps

The following steps demonstrate how to define View and Controller for configuring igTree.

  1. Create an XML data source file.

    Create an XML file for the data with Text, ImageUrl, and Value attributes following this structure:

    In XML:

    <Folder Text="Network" ImageUrl="../content/images/igTree/Common/door.png" Value="Folder">     
               <Folder Text="Archive" ImageUrl="../content/images/igTree/Common/door_in.png" Value="Folder"></Folder>
               <Folder Text="Back Up" ImageUrl="../content/images/igTree/Common/door_in.png" Value="Folder"></Folder>
               <Folder Text="FTP" ImageUrl="../content/images/igTree/Common/door_in.png" Value="Folder"></Folder>
     </Folder>
  2. Define the View.

    1. Add a new View to the Views folder. For this example, name it SampleDataXML.cshtml.

    2. Add the code to initialize the igTree and enable Copy mode in the view.

      In C#:

       <script src="http://localhost/ig_ui/js/infragistics.loader.js" type="text/javascript"></script>
           @(Html
               .Infragistics()
               .Loader()
               .ScriptPath("http://localhost/ig_ui/js/")
               .CssPath("http://localhost/ig_ui/css/")
               .Render()
           )
           @(Html
               .Infragistics()
               .Tree()
               .ID("XMLTree")
               .Bindings(bindings => {
                   bindings
                   .ValueKey("Value")
                   .TextKey("Text")
                   .ImageUrlKey("ImageUrl")
                   .ChildDataProperty("Folder");
               })
               .InitialExpandDepth(0)
               .DataSource(Model)
               .CheckboxMode(CheckboxMode.TriState)
               .SingleBranchExpand(true)
               .DragAndDrop(true)
               .DragAndDropSettings(settings =>
               {
                   // Configuring Drag-and-drop copy mode
                   settings.DragAndDropMode(DragAndDropMode.Copy);
               })
               .DataBind()
               .Render()  
           )
      
  3. Define the controller.

    In C#:

     public class SampleDataXMLController : Controller
         {
             public ActionResult DataBindingUsingMVC()
             {
                 return View("SampleDataXML", this.GetData());
             }
             private IEnumerable<Folders> GetData()
             {
                 string phisicalFilePath = System.Web.HttpContext.Current.Server.MapPath("~/ThreeData.xml");
                 var ctx = XDocument.Load(phisicalFilePath);
                 IEnumerable<Folders> data = from item in ctx.Root.Elements("Folder")
                                             select new Folders
                                             {
                                                 Text = item.Attribute("Text").Value,
                                                 Value = item.Attribute("Value").Value,
                                                 ImageUrl = Url.Content(item.Attribute("ImageUrl").Value),
                                                 Folder = from i1 in item.Elements("Folder")
                                                          select new Folders
                                                          {
                                                              Text = i1.Attribute("Text").Value,
                                                              Value = i1.Attribute("Value").Value,
                                                              ImageUrl = Url.Content(i1.Attribute("ImageUrl").Value),
                                                              Folder = from i2 in i1.Elements("Folder")
                                                                       select new Folders
                                                                       {
                                                                           Text = i2.Attribute("Text").Value,
                                                                           Value = i2.Attribute("Value").Value,
                                                                           ImageUrl = Url.Content(i2.Attribute("ImageUrl").Value),
                                                                           Folder = from i3 in i2.Elements("Folder")
                                                                                    select new Folders
                                                                                    {
                                                                                        Text = i3.Attribute("Text").Value,
                                                                                        Value = i3.Attribute("Value").Value,
                                                                                        ImageUrl = Url.Content(i3.Attribute("ImageUrl").Value)
                                                                                    }
                                                                       }
                                                          }
                                             };
                 return data;
             }
         } 
     public class Folders
     {
             public string Text { get; set; }
             public string Value { get; set; }
             public string ImageUrl { get; set; }
             public IEnumerable<Folders> Folder { get; set; }
     }
    

Related Content

Topics

The following topics provide additional information related to this topic.

Samples

The following samples provide additional information related to this topic.

View on GitHub