[CLOSED] Find Parent Node and Reassign node to founded Parent Node in Tree view

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Find Parent Node and Reassign node to founded Parent Node in Tree view

    Hi all,

    we are trying to find the parent node and then reassign a node to founded parent node in Tree View control. Please find the attached sample page and give me your feedback for following items,
    1. Find the parent node and then reassign the node to founded parent node
    2. Is possible to reassign the node in old poisition(index). If yes then give me a sample. For example, "Order No" node is in "HEAD" root and index is 0. I will add this node to another tree view control under the "FIELDS" root and again i will remove this field from "FIELDS" root and reassign the "HEAD" root in same position (0th index)

    Please give your feedback asap

    Regards

    Rameshkumar.T
    Attached Files
    Last edited by Daniil; Jun 27, 2011 at 12:54 PM. Reason: [CLOSED]
  2. #2
    Hi,

    I can't reproduce the issue. Also I'm even not sure I understand your correctly.

    I see a lot of unrelated to the problem code, please remove it suing this technique:
    How to reduce a sample
  3. #3

    Find Parent Node and Reassign node to founded Parent Node in Tree view

    Hi Daniil,

    I have update source in CODE block. Please check and give your feedback.Also I have attached sample image
    Click image for larger version. 

Name:	treeview.jpg 
Views:	286 
Size:	34.0 KB 
ID:	2899
    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Import Namespace="Coolite.Ext.Web" %>
    <%@ Import Namespace="Coolite.Utilities" %>
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <ext:ScriptContainer ID="ScriptContainer1" runat="server">
        </ext:ScriptContainer>
        <link rel="stylesheet" type="text/css" href="css/ext-all-embedded.css" />
        <link rel="stylesheet" type="text/css" href="css/xtheme-slate.css" />
        <link rel="stylesheet" type="text/css" href="css/common.css" />
        <style type="text/css">
            .head
            {
                color: Red;
            }
            .position
            {
                color: Green;
            }
        </style>
        <script runat="server">
            private class Node
            {
                public Node(string name)
                {
                    this.Name = name;
                }
                public string Name
                {
                    get;
                    set;
                }
                private List<ChildNode> _ChildNodes;
                public List<ChildNode> ChildNodes
                {
                    get
                    {
                        if (this._ChildNodes == null)
                        {
                            this._ChildNodes = new List<ChildNode>();
                        }
                        return this._ChildNodes;
                    }
                }
            }
            private class ChildNode
            {
                public ChildNode()
                {
                }
                public ChildNode(string title)
                {
                    this.Title = title;
                }
                public string Title
                {
                    get;
                    set;
                }
                public string Parent
                {
                    get;
                    set;
                }
            }
            #region Private Methods
            private void BindAvailabeFields()
            {
                this.PlaceHolder1.Controls.Add(trp_left);
                Coolite.Ext.Web.TreeNode root = new Coolite.Ext.Web.TreeNode("FIELDS");
                root.Expanded = true;
                root.AllowDrag = false;
                trp_left.Root.Add(root);
                List<Node> CHead = this.GetHead();
                foreach (Node chead in CHead)
                {
                    Coolite.Ext.Web.TreeNode TNhead = new Coolite.Ext.Web.TreeNode(chead.Name);
                    TNhead.AllowDrag = false;
                    root.Nodes.Add(TNhead);
                    foreach (ChildNode childnode in chead.ChildNodes)
                    {
                        Coolite.Ext.Web.TreeNode objtreenode = new Coolite.Ext.Web.TreeNode(childnode.Title);
                        switch (chead.Name)
                        {
                            case "HEAD":
                                TNhead.IconCls = "head";
                                objtreenode.IconCls = "head";
                                break;
                            case "POSITION":
                                TNhead.IconCls = "position";
                                objtreenode.IconCls = "position";
                                break;
                            case "DETAIL":
                                TNhead.IconCls = "detail";
                                objtreenode.IconCls = "detail";
                                break;
                        }
                        TNhead.Nodes.Add(objtreenode);
                    }
                }
            }
            private void BindTemplateFieldsRoot()
            {
                Coolite.Ext.Web.TreeNode root2 = new Coolite.Ext.Web.TreeNode("FIELDS");
                root2.Expanded = true;
                trp_right.Root.Add(root2);
            }
            private List<Node> GetHead()
            {
                List<ChildNode> childnodelist = new List<ChildNode>();
                ChildNode objchildnode = new ChildNode();
                System.Data.DataView dvFilter = new System.Data.DataView();
                //Assign Head Template
                Node HeadNode = new Node("HEAD");
                string[] arrhead = { "Order No", "Order Date", "Supplier Name" };
                for (int i = 0; i < arrhead.Length; i++)
                {
                    objchildnode = new ChildNode();
                    objchildnode.Title = arrhead[i];
                    objchildnode.Parent = "HEAD";
                    childnodelist.Add(objchildnode);
                }
                HeadNode.ChildNodes.AddRange(childnodelist);
                //Assign Position Template
                childnodelist = new List<ChildNode>();
                Node PositionNode = new Node("POSITION");
                string[] arrpos = { "Quantity", "Amount", "UOM" };
                for (int i = 0; i < arrpos.Length; i++)
                {
                    objchildnode = new ChildNode();
                    objchildnode.Title = arrpos[i];
                    objchildnode.Parent = "POSITION";
                    childnodelist.Add(objchildnode);
                }
                PositionNode.ChildNodes.AddRange(childnodelist);
    
                return new List<Node> { HeadNode, PositionNode };
            }
            #endregion
            #region Event Handlers
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    BindAvailabeFields();
                    BindTemplateFieldsRoot();
                }
            }
            #endregion
        </script>
        <script type="text/javascript">
            function clone(node, destination) {
                var atts = node.attributes;
                atts.id = Ext.id();
                var clonedNode = new Ext.tree.TreeNode(Ext.apply({}, atts));
                clonedNode.text = node.text;
                for (var i = 0; i < node.childNodes.length; i++) {
                    clonedNode.appendChild(clone(node.childNodes[i]));
                }
                var flag = 1;
                for (var i = 0; i < destination.root.childNodes.length; i++) {
                    if (destination.root.childNodes[i].text == node.text) {
                        flag = 0;
                        break;
                    }
                }
                if (flag == 1) {
                    return clonedNode;
                }
                else {
                    return 1;
                }
            }
            var Title = "";
            var msginvalidmove = "";
            function moveNode(source, destination, copy) {
                try {
                    var node = source.getSelectionModel().getSelectedNode();
                    node.id;
                    if (Ext.isEmpty(node)) {
                        top.ShowInformation('1', msginvalidmove, Title);
                        return;
                    }
                    var destionationRoot = destination.getRootNode();
                    var temp;
                    if (copy == true) {
                        temp = clone(node, destination);
                        if (temp != 1) {
                            destionationRoot.appendChild(temp);
                            btndis();
                        }
                    }
                    else {
                        temp = node.remove();
                        destionationRoot.appendChild(temp);
                        btndis();
                    }
                    trp_right.getRootNode().expand();
                }
                catch (e) {
                }
            }
            function btndis() {
                var LV_A = trp_right.getRootNode().childNodes.length;
                var LV_D2 = document.getElementById('img_save');
                if (LV_A != 0) {
                    LV_D2.disabled = false;
                }
                else {
                    LV_D2.disabled = true;
                }
            }
            function moveall() {
                removeall();
                var T = trp_left.root.attributes.children;
                for (var i = 0; i < T.length; i++) {
                    var T1 = T[i].children;
                    if (T1 != null || T1 != undefined) {
                        for (var j = 0; j < T1.length; j++) {
                            var atts = T1[j];
                            atts.id = Ext.id();
                            var cl = new Ext.tree.TreeNode(Ext.apply({}, atts));
                            cl.text = T1[j].text;
                            trp_right.root.appendChild(cl);
                        }
                    }
                }
                trp_right.getRootNode().expand();
                btndis();
            }
            function removeall() {
                var dest = trp_right.getRootNode();
                for (var i = dest.childNodes.length - 1; i >= 0; i--) {
                    temp = dest.childNodes[i].remove();
                }
                btndis();
            }
     
     
    
            var X = {
                add: function(source, destination) {
                    source = source || trp_left;
                    destination = destination || trp_right;
                    var selectedNode = source.getSelectionModel().getSelectedNode();
                    var destinationSelectedNode = destination.getSelectionModel().getSelectedNode();
                    if (selectedNode && destinationSelectedNode == null) {
                        if (!isNumber(selectedNode.id))
                            destination.getRootNode().appendChild(selectedNode);
                        //btnEdit.setDisabled(true);
                    }
                    else if (selectedNode && destinationSelectedNode != null) {
                        if (destinationSelectedNode.getDepth() == "1") {
                            if (!isNumber(destinationSelectedNode.id))
                                destinationSelectedNode.parentNode.appendChild(selectedNode);
                            else
                                destinationSelectedNode.appendChild(selectedNode);
                        }
                        else {
                            destinationSelectedNode.parentNode.appendChild(selectedNode);
                        }
                        destinationSelectedNode.unselect();
                        //btnEdit.setDisabled(true);
                    }
                },
                remove: function(source, destination) {
                    source = source || trp_right;
                    destination = destination || trp_left;
                    var selectedNode = source.getSelectionModel().getSelectedNode();
                    var objparentnode = null;
                    if (selectedNode.attributes.iconCls == 'head') {
                        objparentnode = destination.getNodeById('HEAD');
                    }
                    if (objparentnode != null) {
                        objparentnode.appendChild(selectedNode);
                    }
    
                }
            };
            function isNumber(data) {
                return !isNaN(data - 0);
            }
        </script>
        <style type="text/css">
            .hidd
            {
                visibility: hidden;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <ext:ScriptManager ID="ScriptManager1" runat="server" RenderStyles="File">
            </ext:ScriptManager>
            <ext:ViewPort ID="VP1" runat="server">
                <Body>
                    <ext:BorderLayout ID="BL1" runat="server" StyleSpec="background-color:transparent;">
                        <Center>
                            <ext:Panel ID="Pnl2" runat="server" Border="false" StyleSpec="padding-left:10px;"
                                AutoScroll="true">
                                <Body>
                                    <table border="0" cellpadding="0" cellspacing="5">
                                        <tr>
                                            <td>
                                                <ext:TreePanel ID="trp_left" runat="server" AutoScroll="true" RootVisible="false"
                                                    Width="300" Height="360" AllowLeafDrop="true">
                                                </ext:TreePanel>
                                                <asp:PlaceHolder ID="PlaceHolder1" runat="server" />
                                            </td>
                                            <td>
                                                <table border="0" cellpadding="0" cellspacing="5">
                                                    <tr>
                                                        <td>
                                                            <ext:Button ID="Btn_AddAll" runat="server" IconCls="but_last">
                                                                <Listeners>
                                                                    <Click Handler="moveall();" />
                                                                </Listeners>
                                                            </ext:Button>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            <ext:Button ID="Btn_Add" runat="server" IconCls="but_next">
                                                                <%--<Listeners>
                                                                    <Click Handler="moveNode(#{trp_left}, #{trp_right}, true);" />
                                                                </Listeners>--%>
                                                                <Listeners>
                                                                    <Click Handler="X.add(trp_left, trp_right);" />
                                                                </Listeners>
                                                            </ext:Button>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            <ext:Button ID="Btn_remove" runat="server" IconCls="but_previous">
                                                                <%--<Listeners>
                                                                    <Click Handler="moveNode(#{trp_right}, #{trp_left},false);" />
                                                                </Listeners>--%>
                                                                <Listeners>
                                                                    <Click Handler="X.remove(trp_right,trp_left);" />
                                                                </Listeners>
                                                            </ext:Button>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                            <ext:Button ID="Btn_removeall" runat="server" IconCls="but_first">
                                                                <Listeners>
                                                                    <Click Handler="removeall();" />
                                                                </Listeners>
                                                            </ext:Button>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                            <td>
                                                <ext:TreePanel ID="trp_right" runat="server" AutoScroll="true" Width="300" Height="360">
                                                </ext:TreePanel>
                                            </td>
                                        </tr>
                                    </table>
                                </Body>
                            </ext:Panel>
                        </Center>
                    </ext:BorderLayout>
                </Body>
            </ext:ViewPort>
        </div>
        </form>
    </body>
    </html>
    Quote Originally Posted by Daniil View Post
    Hi,

    I can't reproduce the issue. Also I'm even not sure I understand your correctly.

    I see a lot of unrelated to the problem code, please remove it suing this technique:
    How to reduce a sample
    Last edited by speedstepmem4; Jun 22, 2011 at 4:25 AM. Reason: Add sample image
  4. #4
    I see this view on my screen when run the page.
    Attachment 2901
  5. #5

    Find Parent Node and Reassign node to founded Parent Node in Tree view

    Hi Daniil,

    Please see my source give me a sample to use multiple parent nodes in two tree view.

    Quote Originally Posted by Daniil View Post
    I see this view on my screen when run the page.
    Attachment 2901
  6. #6
    Quote Originally Posted by speedstepmem4 View Post
    Please see my source give me a sample to use multiple parent nodes in two tree view.
    What is "my source"? Do you mean that one you posted before?
  7. #7

    Find Parent Node and Reassign node to founded Parent Node in Tree view

    Yes Alread I have posted
    Quote Originally Posted by Daniil View Post
    What is "my source"? Do you mean that one you posted before?
  8. #8
  9. #9

    Find Parent Node and Reassign node to founded Parent Node in Tree view

    Hi Daniil,

    Herewith i have attached for sample page which has been converted V0.8 to V1.0
    Please review the page and give me your suggestion how to use following query

    Find the parent node when click on Remove button after selected a node in righ side. Also selected a node will be append same poistion under the founded parent node in left side


    Quote Originally Posted by Daniil View Post
    Attached Files
  10. #10
    I was able to run the page.

    Please clarify the requirement.

    It seems that the "Add All", "Remove", "Remove All" buttons work as expected, right?

    And the "Add" button doesn't work at all, right?

    The "Add" button should add a selected in the right tree node to the left tree at the same position this node was in the right tree.

    Am I correct?
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 8
    Last Post: Jun 20, 2012, 6:48 PM
  2. [CLOSED] select node and expand parent nodes
    By LeeTheGreek in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: May 13, 2011, 12:06 PM
  3. Replies: 1
    Last Post: Nov 24, 2010, 3:04 PM
  4. [CLOSED] Get parent node custom attribute
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 14, 2010, 9:19 PM
  5. TreePanel:Copying from one node to another node using drag and drop
    By eighty20 in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Jan 25, 2009, 7:48 AM

Tags for this Thread

Posting Permissions