Available in the OSS Version

Tree - Drag and Drop - Multiple Trees

This sample demonstrates how to drag and drop nodes from one igTree control to another.

This sample is designed for a larger screen size.

On mobile, try rotating your screen, view full size, or email to another device.

Code View

Copy to Clipboard
<!DOCTYPE html>
<html>
<head>
    <title></title>

    <!-- Ignite UI for jQuery Required Combined CSS Files -->
    <link href="http://cdn-na.infragistics.com/igniteui/2024.2/latest/css/themes/infragistics/infragistics.theme.css" rel="stylesheet" />
    <link href="http://cdn-na.infragistics.com/igniteui/2024.2/latest/css/structure/infragistics.css" rel="stylesheet" />

    <style>
        .containerTree {
            overflow: auto;
            width: 100%;
        }

		.containerTree h3 { margin-bottom: 5px; }

        #left {
            display: inline;
            float: left;
            width: 350px;
            margin-right: 30px;
			margin-bottom: 10px;
        }

        #right {
            float: left;
            width: 350px;
			margin-bottom: 10px;
        }

        #firstTree, #secondTree {
            font-size: 14px;
        }

		@media screen and (max-width: 500px) {
    		#left { width: 270px; }
			#right {
				width: 270px;
                clear: both;
            }
        }
    </style>

    <script src="http://ajax.aspnetcdn.com/ajax/modernizr/modernizr-2.8.3.js"></script>
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="http://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>

    <!-- Ignite UI for jQuery Required Combined JavaScript Files -->
    <script src="http://cdn-na.infragistics.com/igniteui/2024.2/latest/js/infragistics.core.js"></script>
    <script src="http://cdn-na.infragistics.com/igniteui/2024.2/latest/js/infragistics.lob.js"></script>

</head>
<body>
    <div class="containerTree">
        <div id="left">
			<h3>File Manager 1</h3>
            <!--igTree target element-->
            <div id="firstTree"></div>
        </div>
        <div id="right">
			<h3>File Manager 2</h3>
            <!--igTree target element-->
            <div id="secondTree"></div>
        </div>
    </div>

    <script src="/data-files/hierarchical-files.js"></script>

    <script>

        $(function () {            

            $("#firstTree").igTree({
                checkboxMode: 'triState',
                singleBranchExpand: true,
                dataSource: $.extend(true, [], files),
                dataSourceType: 'json',
                initialExpandDepth: 0,
                pathSeparator: '.',
                bindings: {
                    textKey: 'Text',
                    valueKey: 'Value',
                    imageUrlKey: 'ImageUrl',
                    childDataProperty: 'Folder'
                },
                dragAndDrop: true,
                dragAndDropSettings: {
                    allowDrop: true,
                    customDropValidation: function (element) {
                        // Validates the drop target
                        var valid = true,
							droppableNode = $(this);

                        if (droppableNode.is('a') && droppableNode.closest('li[data-role=node]').attr('data-value') === 'File') {
                            valid = false;
                        }

                        return valid;
                    }
                }
            });

            $("#secondTree").igTree({
                checkboxMode: 'triState',
                singleBranchExpand: true,
                dataSource: $.extend(true, [], files),
                dataSourceType: 'json',
                initialExpandDepth: 0,
                pathSeparator: '.',
                bindings: {
                    textKey: 'Text',
                    valueKey: 'Value',
                    imageUrlKey: 'ImageUrl',
                    childDataProperty: 'Folder'
                },
                dragAndDrop: true,
                dragAndDropSettings: {
                    allowDrop: true,
                    customDropValidation: function (element) {
                        // Validates the drop target
                        var valid = true,
							droppableNode = $(this);

                        if (droppableNode.is('a') && droppableNode.closest('li[data-role=node]').attr('data-value') === 'File') {
                            valid = false;
                        }

                        return valid;
                    }
                }
            });

        });

    </script>

</body>
</html>