Sep 17, 2013, 6:42 AM
[CLOSED] Refresh Tree Panel
Hello,
I have a TreePanel created on the fly. The problem is that is not refreshing.
I tried the method TreePanel.RemoveAll() and to recreate it but it returns an empty control.
Here is the C# code
Thanks
I have a TreePanel created on the fly. The problem is that is not refreshing.
I tried the method TreePanel.RemoveAll() and to recreate it but it returns an empty control.
Here is the C# code
public void PopulateTree()
{
Ext.Net.Node root = new Ext.Net.Node()
{
Text = "Categories",
};
TreePanel1.Root.Add(root);
var data = RequestCategoriesController.GetRequestCategories();
foreach (DataLayer.RequestCategory item in data.Where(c => c.ParentFK == null))
{
AddNode(root.Children, item, data);
}
}
private void AddNode(NodeCollection nodes, DataLayer.RequestCategory currentCategory, List<DataLayer.RequestCategory> items)
{
Node newNode = new Node()
{
NodeID = currentCategory.SN.ToString(),
Text = currentCategory.Name,
Expanded = true
};
newNode.CustomAttributes.Add(new ConfigItem("SN", currentCategory.SN.ToString()));
newNode.CustomAttributes.Add(new ConfigItem("Name", currentCategory.Name));
newNode.CustomAttributes.Add(new ConfigItem("ParentFK", currentCategory.ParentFK.ToString()));
newNode.CustomAttributes.Add(new ConfigItem("IsActive", currentCategory.IsActive.ToString()));
nodes.Add(newNode);
var children = items.Where(x => x.ParentFK == currentCategory.SN);
if (children.Count() == 0)
newNode.Leaf = true;
foreach (var child in children)
{
AddNode(newNode.Children, child, items);
}
}
public override void CommandReload(object sender, DirectEventArgs e)
{
if (X.IsAjaxRequest)
{
TreePanel1.RemoveAll();
}
}
protected void TreePanel1_PreRender(object sender, EventArgs e)
{
if (X.IsAjaxRequest)
PopulateTree();
else
PopulateTree();
}
Code Behind<ext:TreePanel ID="TreePanel1" OnPreRender="TreePanel1_PreRender"
runat="server"
ForceFit="true"
Region="Center"
UseArrows="true"
RootVisible="false"
MultiSelect="true"
SingleExpand="true"
FolderSort="true">
<Listeners>
<ItemClick Fn="getSN"/>
</Listeners>
<Store>
<ext:TreeStore ID="TreeStore1" runat="server" OnLoad="TreeStore1_Load" >
<Proxy>
<ext:PageProxy />
</Proxy>
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="SN"/>
<ext:ModelField Name="Name" />
<ext:ModelField Name="ParentFK" />
<ext:ModelField Name="IsActive" />
</Fields>
</ext:Model>
</Model>
</ext:TreeStore>
</Store>
<ColumnModel>
<Columns>
<ext:TreeColumn OnPreRender="Unnamed_PreRender"
runat="server"
Text="<%$Resources:DBFields , RequestCategories_Name %>"
Sortable="true"
DataIndex="Name">
<Renderer*Fn="Link"/>
</ext:TreeColumn>
<ext:CheckColumn ID="Column3"
runat="server"
Text="<%$Resources:DBFields , RequestCategories_IsActive %>"
Sortable="true"
DataIndex="IsActive" />
</Columns>
</ColumnModel>
</ext:TreePanel>
Any idea on how I could refresh the TreePanel?Thanks
Last edited by Daniil; Sep 25, 2013 at 5:24 AM.
Reason: [CLOSED]