[CLOSED] how to reload treepanel after adding a record?

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] how to reload treepanel after adding a record?

      <ext:TreeStore runat="server" ID="ts_infocate" OnReadData="ReloadData">
                                <Model>
                                    <ext:Model ID="Model1" runat="server">
                                        <Fields>
                                            <ext:ModelField Name="id">
                                            </ext:ModelField>
                                            <ext:ModelField Name="cate">
                                            </ext:ModelField>
                                            <ext:ModelField Name="pid">
                                            </ext:ModelField>
                                            <ext:ModelField Name="grade">
                                            </ext:ModelField>
                                        </Fields>
                                    </ext:Model>
                                </Model>
                            </ext:TreeStore>
     protected void AddCate(object sender, DirectEventArgs e)
            {
                var pid = ddf_pid.Value.ToString();
                var cate = tf_cate.Value.ToString();
                var grade = tf_grade.Value.ToString();
                var infocate = new QizInfoCate();
                infocate.pid = int.Parse(pid);
                infocate.cate = cate;
                infocate.grade = int.Parse(grade);
                infoCateDao.Add(infocate);
                w_add.Hide();
                ts_infocate.Reload();//here reload , but the treepanel's empty after execute it. why? how to reload treepanel?
            }
    
            protected void ReloadData(object sender, NodeLoadEventArgs e)  //
            {
                Loadinfocates(tp_infocate); // this load data to treepanel 
                tp_infocate.ExpandAll(); //expand the node.
            }
    Last edited by Daniil; May 13, 2014 at 4:14 PM. Reason: [CLOSED]
  2. #2
    Hi @hdsoso,

    You should use
    this.TreePanel1.ReloadNode("NodeID");
    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void NodeLoad(object sender, NodeLoadEventArgs e)
        {
            string prefix = e.ExtraParams["prefix"] ?? "";
    
            if (!string.IsNullOrEmpty(e.NodeID))
            {
                for (int i = 1; i < 6; i++)
                {
                    Node asyncNode = new Node();
                    asyncNode.Text = prefix + e.NodeID + i;
                    asyncNode.NodeID = e.NodeID + i;
                    e.Nodes.Add(asyncNode);
                }
    
                for (int i = 6; i < 11; i++)
                {
                    Node treeNode = new Node();
                    treeNode.Text = prefix + e.NodeID + i;
                    treeNode.NodeID = e.NodeID + i;
                    treeNode.Leaf = true;
                    e.Nodes.Add(treeNode);
                }
            }
        }
    
        protected void Button_DirectClick(object sender, DirectEventArgs e)
        {
            this.TreePanel1.ReloadNode("0");
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>TreePanel using PageProxy - Ext.NET Examples</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
            <ext:Button runat="server" Text="Reload" OnDirectClick="Button_DirectClick" />
    
            <ext:TextField ID="TextField1" runat="server" Text="Node" Width="200" />
            
            <ext:TreePanel 
                ID="TreePanel1" 
                runat="server" 
                Title="Tree"
                Width="200"
                Height="500" 
                Border="false">
                <Store>
                    <ext:TreeStore runat="server" OnReadData="NodeLoad">
                        <Proxy>
                            <ext:PageProxy />
                        </Proxy>
                        <Parameters>
                            <ext:StoreParameter Name="prefix" Value="#{TextField1}.getValue()" Mode="Raw" />
                        </Parameters>
                    </ext:TreeStore>
                </Store>
                <Root>
                    <ext:Node NodeID="0" Text="Root" />
                </Root>
            </ext:TreePanel>       
        </form>
    </body>
    </html>
  3. #3
    i run your example , but your example is loading data after clicking one node, the mehod can not expand all the tree node one page is loaded.

    my way is :
    when page is loaded , i create nodes for the the panel according database , then i click add button , show a window for adding a record to the database , i do not add the node to the tree panel , so i want to reload the treepanel from database the same as the page is loaded again , how to do ?

    another one i do not know,OnReadData event for the treestore, dose it execute every time when page is loading?
    i add creading nodes to the onreaddata event handler , and i add pageproxy to the treestore, why it dose not execute when page is loading ? my code above , i place creading nodes to page_load .
    Last edited by hdsoso; Apr 30, 2014 at 2:14 AM.
  4. #4
    Quote Originally Posted by hdsoso View Post
    i run your example , but your example is loading data after clicking one node, the mehod can not expand all the tree node one page is loaded.
    I just demonstrated a way how to reload a TreePanel. It seems what you asked. Does it not work for you?

    Quote Originally Posted by hdsoso View Post
    another one i do not know,OnReadData event for the treestore, dose it execute every time when page is loading?
    It should be executed if some Node is expanding.

    Please provide a sample to reproduce the problem. You can take my sample and change it according to your scenario.
  5. #5
    Quote Originally Posted by hdsoso View Post
    my way is :
    when page is loaded , i create nodes for the the panel according database , then i click add button , show a window for adding a record to the database , i do not add the node to the tree panel , so i want to reload the treepanel from database the same as the page is loaded again , how to do ?
    do you mean?
  6. #6
    or can you give me an example below .

    a treepanel in the page , when page is loaded , nodes of treepanel is expanded all , then click a add button , then show a window , the window contains a formpanel , submit the formpanel , i add a record to the database , notice i just operate the database , i do not operate the three panel , so at last ,i just reload the page to read the database again so that the record can show in the treepanel .

    do you know want i mean? i want to know how to reload the page?
  7. #7
    Please post a simplified sample demonstrating as much of the scenario as possible. Remove all code that is not directly related to the problem. If we copy and paste your sample into our test project and have to fix error just to get your sample to run, you will not get a response.

    Please do not post in the forums again without reading the following two Guideline documents:

    http://forums.ext.net/showthread.php...ing-New-Topics

    http://forums.ext.net/showthread.php...ation-Required

    You should also read the following post:

    http://forums.ext.net/showthread.php...l=1#post148801

    At this point you have posted 289 times in these forums. You know how things work around here. Please read the Guidelines and follow them.
    Geoffrey McGill
    Founder & CEO
  8. #8
    i wrote a sample below, click add button, select the root parent node, and type a type name , then click submit, the window will hide, but the treepanel and treestore dose not reload. how to do?
    <%@ Page Language="C#" %>
    
    <!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>
        <script runat="server">
             
            // InfoCateDao infoCateDao = new InfoCateDao();
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!X.IsAjaxRequest)
                {
                    DbClass db = new DbClass();
                    var nodes = db.NodesList;
                    Loadinfocates(ts_infocate, nodes);
                    //   tp_infocate.ExpandAll();
                    Loadinfocates(ts_cates,nodes);
                    //  tp_cates.ExpandAll();
                }
            }
            public class NodeRow
            {
                public int id { get; set; }
                public string cate { get; set; }
                public int pid { get; set; }
                public string grade { get; set; }
            }
    
            public class DbClass
            {
                public List<NodeRow> NodesList;
    
                public DbClass()
                {
                    NodesList = new List<NodeRow>
                    {
                        new NodeRow{id = 1,cate = "cate1",grade = "1",pid = -1}
                    };
                }
    
                public void put(NodeRow nr)
                {
                    this.NodesList.Add(nr);
                }
            }
    
    
            protected void ShowAddWindow(object sender, DirectEventArgs e)
            {
                w_add.Show();
            }
            private void Loadinfocates(TreeStore ts, List<NodeRow> nodesList)
            {
                var root = new Node { NodeID = "-1", Text = "根类别", Expanded = true };
                root.CustomAttributes.AddRange(new List<ConfigItem>
                {
                    new ConfigItem { Name = "id", Value = "-1" },new ConfigItem { Name = "cate", Value = "根类别" }
                });
                ts.Root.Add(root);
    
                foreach (var node in nodesList)
                {
                    var n = new Node { Text = node.cate, Leaf = true };
    
                    n.CustomAttributes.AddRange(new List<ConfigItem>
                     {
                         new ConfigItem {Name = "id", Value = node.id.ToString()},
                         new ConfigItem {Name = "cate", Value = node.cate},
                         new ConfigItem {Name = "pid", Value = node.pid.ToString()},
                         new ConfigItem {Name = "grade", Value =node.grade}
                     });
                    root.Children.Add(n);
                }
    
            }
    
            protected void AddCate(object sender, DirectEventArgs e)
            {
                var pid = ddf_pid.Value.ToString();
                var cate = tf_cate.Value.ToString();
                var grade = tf_grade.Value.ToString();
                //  var infocate = new QizInfoCate();
                //  infocate.pid = int.Parse(pid);
                // infocate.cate = cate;
                //  infocate.grade = int.Parse(grade);
                //  infoCateDao.Add(infocate);
                //Node n =  ts_infocate.node
                DbClass db = new DbClass();
                db.put(new NodeRow { pid = -1, cate = cate, grade = "1",id = 2});
    
                var nodes = db.NodesList;
    
                Loadinfocates(ts_infocate,nodes);
                w_add.Hide();
    
            }
    
            protected void ReloadData(object sender, NodeLoadEventArgs e)
            {
                // Loadinfocates(ts_infocate);
                // tp_infocate.ExpandAll();
            }
    
            private void Loadsubcaes(Node parentNode, int pid)
            {
                //var cates = infoCateDao.InfoCatesByPid(pid);
                // foreach (var qizInfoCate in cates)
                // {
                //     bool leaf = infoCateDao.Isleaf(qizInfoCate.id);
                //     var n = new Node { Text = qizInfoCate.cate, Leaf = leaf };
    
                //     n.CustomAttributes.AddRange(new List<ConfigItem>
                //     {
                //         new ConfigItem {Name = "id", Value = qizInfoCate.id.ToString()},
                //         new ConfigItem {Name = "cate", Value = qizInfoCate.cate},
                //         new ConfigItem {Name = "pid", Value = qizInfoCate.pid.ToString()},
                //         new ConfigItem {Name = "grade", Value = qizInfoCate.grade.ToString()}
                //     });
                //     parentNode.Children.Add(n);
                //     Loadsubcaes(n, qizInfoCate.id);
                // }
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager runat="server" SourceFormatting="True">
            </ext:ResourceManager>
    
            <ext:Window runat="server" Hidden="True" ID="w_add" Title="新增类别" Width="310" Layout="HBoxLayout">
                <LayoutConfig>
                    <ext:HBoxLayoutConfig Pack="Center" />
                </LayoutConfig>
                <Items>
                    <ext:FormPanel runat="server" Layout="AnchorLayout" Width="300" Padding="4" ID="fp_add">
                        <Defaults>
                            <ext:Parameter Name="LabelWidth" Value="60" />
                            <ext:Parameter Name="Padding" Value="4" />
                        </Defaults>
                        <Items>
                            <ext:DropDownField runat="server" ID="ddf_pid" AnchorHorizontal="100%" Mode="ValueText" TriggerIcon="SimpleArrowDown" Editable="false" FieldLabel="父类别">
                                <Component>
                                    <ext:TreePanel runat="server" ID="tp_cates" RootVisible="True">
                                        <Store>
                                            <ext:TreeStore runat="server" ID="ts_cates">
                                                <Model>
                                                    <ext:Model ID="Model1" runat="server">
                                                        <Fields>
                                                            <ext:ModelField Name="id">
                                                            </ext:ModelField>
                                                            <ext:ModelField Name="cate">
                                                            </ext:ModelField>
                                                            <ext:ModelField Name="pid">
                                                            </ext:ModelField>
                                                            <ext:ModelField Name="grade">
                                                            </ext:ModelField>
                                                        </Fields>
                                                    </ext:Model>
                                                </Model>
                                            </ext:TreeStore>
                                        </Store>
    
                                        <ColumnModel>
                                            <Columns>
                                                <ext:TreeColumn runat="server" DataIndex="cate" Text="类别" Flex="1">
                                                </ext:TreeColumn>
                                            </Columns>
                                        </ColumnModel>
                                        <Listeners>
                                            <ItemClick Handler="
                                                            this.dropDownField.setValue(record.data.id, record.data.cate, false);
                                                            this.dropDownField.collapse();
                                                            var grade = record.data.grade;
                                                            #{tf_grade}.setValue(grade+1); 
                                                            ">
                                            </ItemClick>
                                        </Listeners>
                                    </ext:TreePanel>
                                </Component>
                            </ext:DropDownField>
                            <ext:TextField ID="tf_cate" runat="server" FieldLabel="类别" AnchorHorizontal="100%"></ext:TextField>
                            <ext:TextField runat="server" ID="tf_grade" FieldLabel="级别" ReadOnly="True" AnchorHorizontal="100%"></ext:TextField>
                        </Items>
                        <Buttons>
                            <ext:Button runat="server" Text="取消">
                                <Listeners>
                                    <Click Handler="#{fp_add}.reset();"></Click>
                                </Listeners>
                            </ext:Button>
                            <ext:Button runat="server" Text="确定">
                                <DirectEvents>
                                    <Click OnEvent="AddCate"></Click>
                                </DirectEvents>
                            </ext:Button>
                        </Buttons>
                    </ext:FormPanel>
                </Items>
            </ext:Window>
    
            <ext:Viewport runat="server" Layout="FitLayout">
                <Items>
                    <ext:TreePanel runat="server" ID="tp_infocate" RootVisible="False">
                        <Store>
                            <ext:TreeStore runat="server" ID="ts_infocate" OnReadData="ReloadData">
                                <Model>
                                    <ext:Model ID="Model2" runat="server">
                                        <Fields>
                                            <ext:ModelField Name="id">
                                            </ext:ModelField>
                                            <ext:ModelField Name="cate">
                                            </ext:ModelField>
                                            <ext:ModelField Name="pid">
                                            </ext:ModelField>
                                            <ext:ModelField Name="grade">
                                            </ext:ModelField>
                                        </Fields>
                                    </ext:Model>
                                </Model>
                                <Proxy>
                                    <ext:PageProxy></ext:PageProxy>
                                </Proxy>
                            </ext:TreeStore>
                        </Store>
                        <TopBar>
                            <ext:Toolbar runat="server">
                                <Items>
    
    
                                    <ext:Button runat="server" Text="新增" Icon="Add">
                                        <DirectEvents>
                                            <Click OnEvent="ShowAddWindow"></Click>
                                        </DirectEvents>
                                    </ext:Button>
                                    <ext:Button runat="server" Text="删除" Icon="Delete">
                                    </ext:Button>
                                    <ext:Button ID="Button1" runat="server" Text="存盘" Icon="Disk">
                                    </ext:Button>
                                    <ext:Button runat="server" Text="展开" Icon="SectionExpanded">
                                        <Listeners>
                                            <Click Handler="#{tp_infocate}.expandAll();">
                                            </Click>
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button runat="server" Text="收缩" Icon="SectionCollapsed">
                                        <Listeners>
                                            <Click Handler="#{tp_infocate}.collapseAll();">
                                            </Click>
                                        </Listeners>
                                    </ext:Button>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                        <ColumnModel>
                            <Columns>
                                <ext:Column runat="server" DataIndex="id" Text="编号">
                                </ext:Column>
                                <ext:TreeColumn runat="server" DataIndex="cate" Text="类别" Flex="1">
                                </ext:TreeColumn>
                                <ext:Column runat="server" DataIndex="grade" Text="级别">
                                </ext:Column>
                                <ext:Column ID="Column1" runat="server" DataIndex="pid" Text="父类别">
                                </ext:Column>
                            </Columns>
                        </ColumnModel>
                        <Plugins>
                            <ext:CellEditing ID="CellEditing1" runat="server" />
                        </Plugins>
                        <SelectionModel>
                            <ext:TreeSelectionModel ID="RowSelectionModel1" runat="server" Mode="Multi">
                            </ext:TreeSelectionModel>
                        </SelectionModel>
                    </ext:TreePanel>
                </Items>
            </ext:Viewport>
        </form>
    </body>
    </html>
  9. #9
    Thank you.

    This line
    ts.Root.Add(root);
    doesn't produce anything during a DirectEvent.

    To get it working you can re-render the TreePanel.

    Please set up
    ID="Viewport1"
    and
    protected void AddCate(object sender, DirectEventArgs e)
    {
        ...
        Loadinfocates(ts_infocate,nodes);
        tp_infocate.Render();
        ... 
    }
  10. #10
    thank your reply, it is working in my example , but it is not working in my real project.
    please my video
    http://screencast.com/t/qbsE6S5vES5H
    i just want to reload the page . now i add a line to my real project
    protected void AddCate(object sender, DirectEventArgs e)
            {
                var pid = ddf_pid.Value.ToString();
                var cate = tf_cate.Value.ToString();
                var grade = tf_grade.Value.ToString();
                var infocate = new QizInfoCate();
                infocate.pid = int.Parse(pid);
                infocate.cate = cate;
                infocate.grade = int.Parse(grade);
                infoCateDao.Add(infocate);
              //  tp_infocate.Render();
                w_add.Hide();
                X.AddScript("window.location.href='infocates.aspx';");   //here is my code added, it is working , but is there ext.net alternative?
              //  ts_infocate.Reload(); 
            }
    Last edited by geoffrey.mcgill; May 04, 2014 at 5:50 AM.
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 4
    Last Post: Jul 12, 2013, 10:07 PM
  2. [CLOSED] Adding a new grid record
    By adelaney in forum 2.x Legacy Premium Help
    Replies: 8
    Last Post: Jun 06, 2012, 3:14 PM
  3. [CLOSED] [1.0] Store adding record
    By state in forum 1.x Legacy Premium Help
    Replies: 14
    Last Post: Dec 11, 2009, 6:24 PM
  4. [CLOSED] Adding a new Store Record - Not a Record object
    By Steve in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: May 15, 2009, 7:40 AM
  5. Adding one record in a grid
    By nuno_Santos in forum 1.x Help
    Replies: 1
    Last Post: Apr 14, 2009, 5:55 PM

Posting Permissions