PDA

View Full Version : [CLOSED] how to reload treepanel after adding a record?



hdsoso
Apr 29, 2014, 4:48 PM
<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.
}

Daniil
Apr 29, 2014, 8:17 PM
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>

hdsoso
Apr 30, 2014, 3:08 AM
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 .

Daniil
Apr 30, 2014, 12:56 PM
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?



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.

hdsoso
Apr 30, 2014, 3:08 PM
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?

hdsoso
Apr 30, 2014, 3:15 PM
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?

geoffrey.mcgill
Apr 30, 2014, 8:58 PM
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?3440-Forum-Guidelines-For-Posting-New-Topics

http://forums.ext.net/showthread.php?10205-More-Information-Required

You should also read the following post:

http://forums.ext.net/showthread.php?33071-CLOSED-Custom-sort-on-some-of-the-grid-columns&p=148801&viewfull=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.

hdsoso
May 01, 2014, 4:24 AM
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>

Daniil
May 01, 2014, 9:59 PM
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();
...
}

hdsoso
May 04, 2014, 1:50 AM
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();
}

geoffrey.mcgill
May 04, 2014, 6:52 AM
X.AddScript("window.location.href='infocates.aspx';"); //here is my code added, it is working , but is there ext.net alternative?

You can try X.Redirect("...").

As well, please use the "Reply to Thread" button, not the "Reply With Quote" button, when adding a post.

Daniil
May 05, 2014, 5:58 AM
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


Well, hard to say.



i just want to reload the page . now i add a line to my real project


X.AddScript("window.location.href='infocates.aspx';"); //here is my code added, it is working , but is there ext.net alternative?


You can use

X.Redirect("infocates.aspx");