Problems with Reload/Databind in TreeGrid with PageTreeLoader defined

  1. #1

    Problems with Reload/Databind in TreeGrid with PageTreeLoader defined

    Hi,

    I have the following example with a TreeGrid:




    
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="TreeGridExample.WebForm1" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">
        public class EntityWithOrder
        {
            public int ID { get; set; }
            public string Name { get; set; }
            public int Order { get; set; }
            public int MotherID { get; set; }
        }
    
        private List<EntityWithOrder> nodes = new List<EntityWithOrder>();
    
        protected void Page_Load(object sender, EventArgs e)
        {
            nodes.Add(new EntityWithOrder { ID = 1, Name = "1", Order = 1, MotherID = 0 });
            nodes.Add(new EntityWithOrder { ID = 2, Name = "2", Order = 1, MotherID = 1 });
            nodes.Add(new EntityWithOrder { ID = 3, Name = "3", Order = 2, MotherID = 1 });
            nodes.Add(new EntityWithOrder { ID = 4, Name = "4", Order = 3, MotherID = 1 });
    
            nodes.Add(new EntityWithOrder { ID = 5, Name = "5", Order = 2, MotherID = 0 });
            nodes.Add(new EntityWithOrder { ID = 6, Name = "6", Order = 1, MotherID = 5 });
            nodes.Add(new EntityWithOrder { ID = 7, Name = "7", Order = 2, MotherID = 5 });
            nodes.Add(new EntityWithOrder { ID = 8, Name = "8", Order = 1, MotherID = 6 });
    
            nodes.Add(new EntityWithOrder { ID = 9, Name = "9", Order = 3, MotherID = 0 });
            nodes.Add(new EntityWithOrder { ID = 10, Name = "10", Order = 1, MotherID = 9 });
            nodes.Add(new EntityWithOrder { ID = 11, Name = "11", Order = 1, MotherID = 10 });
            nodes.Add(new EntityWithOrder { ID = 12, Name = "12", Order = 2, MotherID = 10 });
            nodes.Add(new EntityWithOrder { ID = 13, Name = "13", Order = 3, MotherID = 10 });
            nodes.Add(new EntityWithOrder { ID = 14, Name = "14", Order = 1, MotherID = 12 });
            nodes.Add(new EntityWithOrder { ID = 15, Name = "15", Order = 2, MotherID = 12 });
            nodes.Add(new EntityWithOrder { ID = 16, Name = "16", Order = 1, MotherID = 15 });
    
            nodes.Add(new EntityWithOrder { ID = 17, Name = "17", Order = 4, MotherID = 0 });
            nodes.Add(new EntityWithOrder { ID = 18, Name = "18", Order = 1, MotherID = 17 });
            nodes.Add(new EntityWithOrder { ID = 19, Name = "19", Order = 2, MotherID = 17 });
    
            nodes.Add(new EntityWithOrder { ID = 20, Name = "20", Order = 5, MotherID = 0 });
            nodes.Add(new EntityWithOrder { ID = 21, Name = "21", Order = 1, MotherID = 20 });
        }
    
        protected void LoadNode(object sender, NodeLoadEventArgs e)
        {
            int parsedValue = 0;
            int.TryParse(e.NodeID, out parsedValue);
    
            IList<EntityWithOrder> lst = nodes.Where(n => n.MotherID == parsedValue).ToList();
    
            if (lst.Any())
            {
                List<Ext.Net.TreeNode> l = new List<Ext.Net.TreeNode>();
    
                foreach (EntityWithOrder item in lst)
                {
                    Ext.Net.TreeNode treeNode = new Ext.Net.TreeNode();
    
                    treeNode.IconCls = "iconeTreeGrid";
                    treeNode.NodeID = item.ID.ToString();
                    treeNode.CustomAttributes.Add(new ConfigItem { Name = "ID", Value = item.ID.ToString(), Mode = ParameterMode.Value });
                    treeNode.CustomAttributes.Add(new ConfigItem { Name = "Name", Value = item.Name, Mode = ParameterMode.Value });
                    treeNode.CustomAttributes.Add(new ConfigItem { Name = "Order", Value = item.Order.ToString(), Mode = ParameterMode.Value });
    
                    l.Add(treeNode);
                }
    
                e.Nodes.AddRange(l);
            }
        }
    
        protected void ReorderTwoNodes(object sender, DirectEventArgs e)
        {
            var node9 = nodes.Single(n => n.ID == 9);
            var node17 = nodes.Single(n => n.ID == 17);
    
            node9.Order = 4;
            node17.Order = 3;
    
            _tree.Reload();
            //_tree.DataBind();
        }
            
    </script>
    <!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>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager runat="server" />
        <ext:Button Text="Reorder" runat="server">
            <DirectEvents>
                <Click OnEvent="ReorderTwoNodes" />
            </DirectEvents>
        </ext:Button>
        <ext:TreeGrid ID="_tree" runat="server" UseArrows="true" AutoWidth="true"
            Height="500" noleaficon="false" EnableDD="false" RootVisible="false" EnableSort="false">
            <Columns>
                <ext:TreeGridColumn Header="ID" Width="230" DataIndex="ID" />
                <ext:TreeGridColumn Header="Name" Width="230" DataIndex="Name" />
                <ext:TreeGridColumn Header="Order" Width="230" DataIndex="Order" />
            </Columns>
            <Loader>
                <ext:PageTreeLoader OnNodeLoad="LoadNode" />
            </Loader>
        </ext:TreeGrid>
        </form>
    </body>
    </html>



    I need to reposition(Reorder) some nodes according to the order, after this i need to reload the TreeGrid to take the nodes with the new nodes, but this way don't work.

    How can i Re-DataBind(Reload) the TreeGrid?


    Thanks in advance,
  2. #2

    Hey!

    Hi,

    That's exactly what i need. Can someone reply that?

    Thanks in advance,
  3. #3
    Hi,

    For reorder you have to reload parent node and returns children are soreted as required

    Javascript
    TreeGrid1.getNodeById('9').parentNode.reload();
    That javascript intiate loader request (LoadNode will be executed on the server side)
    Vladimir Shcheglov
    Sr. Developer
  4. #4

    Ty a lot...

    Ty...

    in my case i just needed to reload the itens from the bank... just used:

    X.Call(_treeGrid.ClientID + ".getRootNode().reload");
    Ty, ty....
  5. #5

    Thanks

    Hi, Thanks,

    This works great!

Similar Threads

  1. Replies: 0
    Last Post: Apr 18, 2012, 6:48 PM
  2. [CLOSED] TreeGrid DataBind
    By csharpdev in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Nov 30, 2010, 11:37 AM
  3. Replies: 7
    Last Post: Oct 06, 2010, 6:44 PM
  4. Replies: 2
    Last Post: Nov 02, 2009, 8:27 AM
  5. Databind / Reload Store and GridPanel Problem
    By locoperoguapo in forum 1.x Help
    Replies: 5
    Last Post: Feb 10, 2009, 9:23 AM

Posting Permissions