PDA

View Full Version : [CLOSED] Refresh Tree Panel



S.KARATHANASIS
Sep 17, 2013, 7:42 AM
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


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

Daniil
Sep 17, 2013, 1:01 PM
Hi @S.KARATHANASIS,

If you use a PageProxy, it is supposed that you should load the nodes via a TreeStore's OnReadData handler.
http://examples2.ext.net/#/TreePanel/Loaders/Page/

As far as I can see you are populating a TreePanel's Root. So, you probably do not need a PageProxy. Maybe, you need something like this:
http://examples2.ext.net/#/TreePanel/Basic/Refresh_Static_Tree/

S.KARATHANASIS
Sep 17, 2013, 3:04 PM
Hello Daniil,

Thanks for the reply. It was very helpful.