Nov 11, 2012, 10:21 PM
[CLOSED] Refresh TreePanel
We created our TreePanel in the markup and created the individual nodes dynamically on the server-side. We have a refresh button that when clicked we need to fully update the TreePanel with new nodes. Thought this was going to be easy, but we had trouble getting the TreePanel to show the new nodes.
After searching the forum I found the thread Refresh TreePanel Server Side from Oct 16, 2012 and you suggested looking at the example Tree Panel -> Basic -> Refresh Static Tree.
Below is a sample that I put together:
After searching the forum I found the thread Refresh TreePanel Server Side from Oct 16, 2012 and you suggested looking at the example Tree Panel -> Basic -> Refresh Static Tree.
- Is performing the update via a Direct Method the preferred solution?
- Is there a way via a direct event?
Below is a sample that I put together:
<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html >
<html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
BuildOverviewTree();
}
[DirectMethod]
public string RefreshTree()
{
Ext.Net.NodeCollection nodes = new NodeCollection();
Ext.Net.Node root = new Ext.Net.Node();
root.Text = "root";
//rootNode.Expanded = true;
nodes.Add(root);
Ext.Net.Node personNode = new Ext.Net.Node();
personNode.Text = "John Lee Smith";
personNode.Icon = Icon.User;
personNode.Leaf = false;
ConfigItem ci = new ConfigItem();
ci.Name = "Value";
ci.Value = JSON.Serialize("Parent");
personNode.CustomAttributes.Add(ci);
root.Children.Add(personNode);
Ext.Net.Node kidNode = new Ext.Net.Node();
kidNode.Text = "Bobby Smith";
kidNode.Icon = Icon.UserBrown;
kidNode.Leaf = false;
kidNode.CustomAttributes.Add(new ConfigItem("Value", JSON.Serialize("Child")));
personNode.Children.Add(kidNode);
Ext.Net.Node sportNode = new Ext.Net.Node();
sportNode.Text = "Soccer";
sportNode.Icon = Icon.SportSoccer;
sportNode.Leaf = true;
sportNode.CustomAttributes.Add(new ConfigItem("Value", JSON.Serialize("Sport")));
kidNode.Children.Add(sportNode);
return nodes.ToJson();
}
private void BuildOverviewTree()
{
var random = new Random();
Ext.Net.TreePanel YearPanel = YearPanel01;
Ext.Net.Node rootNode = new Ext.Net.Node();
rootNode.NodeID = "root";
rootNode.Expanded = true;
YearPanel.Root.Clear();
YearPanel.Root.Add(rootNode);
for (int yeardt = 2005; yeardt <= 2012; yeardt++)
{
// Prepare the YEAR Node
Ext.Net.Node yearNode = new Ext.Net.Node()
{
Text = yeardt.ToString(),
Icon = Icon.Calendar,
CustomAttributes =
{
new ConfigItem("Value", yeardt.ToString()),
},
Expanded = false,
};
// Prepare the PENDING Requests Node
double pendingRequests = Math.Floor(Math.Max(random.NextDouble() * 100, 0));
Ext.Net.Node pendingNode = new Ext.Net.Node()
{
Text = "Pending - " + pendingRequests.ToString(),
Icon = Icon.BookOpen,
CustomAttributes =
{
new ConfigItem("Value", "Pending", ParameterMode.Value ),
},
Expanded = false
};
if (pendingRequests > 50)
{
double unassignedRequests = Math.Floor(Math.Max(random.NextDouble() * pendingRequests, 0));
Ext.Net.Node unassignedNode = new Ext.Net.Node()
{
Text = "Unassigned - " + unassignedRequests.ToString(),
Icon = Icon.UserAlert,
CustomAttributes =
{
new ConfigItem("Value", "Unassigned", ParameterMode.Value ),
},
Leaf = true
};
pendingNode.Children.Add(unassignedNode);
}
else
pendingNode.Leaf = true;
yearNode.Children.Add(pendingNode);
// Prepare the CLOSED Request Node
double closedRequests = Math.Floor(Math.Max(random.NextDouble() * 400, 0));
Ext.Net.Node closedNode = new Ext.Net.Node()
{
Text = "Closed - " + closedRequests.ToString(),
Icon = Icon.BookRed,
CustomAttributes =
{
new ConfigItem("Value", "Closed", ParameterMode.Value ),
new ConfigItem("Level", "Open", ParameterMode.Value ),
},
Expanded = false,
Leaf = true
};
yearNode.Children.Add(closedNode);
rootNode.Children.Add(yearNode);
}
}
</script>
<head runat="server">
<title></title>
</head>
<body>
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<form id="form1" runat="server">
<ext:Panel ID="Info" runat="server" Title="Info" Width="300" Height="100" Layout="FitLayout"
BodyPadding="5" ClientIDMode="Static" />
<ext:Panel ID="Overview" runat="server" Title="OverView" Width="300" Height="400"
Layout="FitLayout">
<HtmlBin>
<script type="text/javascript">
var overviewByYearClicked = function (panel, record) {
var aoText = "All";
var aoIcon = "icon-user";
var statusText = "All";
var statusIcon = "icon-book";
var node = record;
for (var i = record.data.depth; i >= 1; i--) {
switch (i) {
case 3:
aoText = node.raw["Value"];
aoIcon = node.raw["iconCls"];
break;
case 2:
statusText = node.raw["Value"];
statusIcon = node.raw["iconCls"];
break;
case 1:
var yearText = node.raw["Value"];
var yearIcon = node.raw["iconCls"];
break;
}
node = node.parentNode;
}
App.Info.update('Year: <b>' + yearText + ' | ' + yearIcon + '</b>' + '</br>' +
'Status: <b>' + statusText + ' | ' + statusIcon + '</b>' + '</br>' +
'AO: <b>' + aoText + ' | ' + aoIcon + '</b>');
}
</script>
<script>
var refreshTree = function (tree) {
App.direct.RefreshTree({
success: function (result) {
var nodes = eval(result);
if (nodes.length > 0) {
tree.setRootNode(nodes[0]);
}
else {
tree.getRootNode().removeAll();
}
}
});
};
</script>
</HtmlBin>
<Items>
<ext:TreePanel ID="YearPanel01" runat="server" Title="By Year" Icon="Calendar" BodyPadding="5"
RootVisible="false">
<Root>
<ext:Node Text="Root" Leaf="true" />
</Root>
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:ToolbarFill ID="ToolbarFill1" runat="server" />
<ext:Button runat="server" Icon="ApplicationCascade" ToolTip="Expand">
<Listeners>
<Click Handler="#{YearPanel01}.expandAll();" />
</Listeners>
</ext:Button>
<ext:Button runat="server" Icon="Application" ToolTip="Collapse">
<Listeners>
<Click Handler="#{YearPanel01}.collapseAll();" />
</Listeners>
</ext:Button>
<ext:Button runat="server" Icon="ArrowRefresh" ToolTip="Refresh" Handler="refreshTree(#{YearPanel01})" />
</Items>
</ext:Toolbar>
</TopBar>
<Listeners>
<ItemClick Fn="overviewByYearClicked" />
</Listeners>
</ext:TreePanel>
</Items>
</ext:Panel>
</form>
</body>
</html>
Last edited by Daniil; Nov 15, 2012 at 3:02 PM.
Reason: [CLOSED]