PDA

View Full Version : [CLOSED] Reloading a TreePanel with new Parameters



chulcy
Mar 17, 2014, 6:29 AM
I have a simple TreePanel using a TreeStore that is using a Proxy to a simple WebService. The WebService requires a parameter. On the initial load, the TreePanel populates correctly.
My problem is when adding a Button that is using it's OnClientClick to change the parameter for the TreeStore. How can I make the TreePanel re-render itself with the new values from the webservice?

Here is my code:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ExtNetTreePanel.aspx.cs" Inherits="adpass.client.extnet.ExtNetTreePanel" %>
<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ExtNetTreePanel Example</title>
<script>
function getJsonResponseData(response) {
try {
return this.readRecords(Ext.decode(Ext.decode(response.re sponseText).d));
} catch (ex) {
var error = new Ext.data.ResultSet({
total: 0,
count: 0,
records: [],
success: false,
message: ex.message
});

this.fireEvent('exception', this, response, error);

return error;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server" />

<h1>TreePanel using WebService</h1>

<ext:Container runat="server"
Layout="HBoxLayout">
<Items>
<ext:TreePanel
ID="treePanel"
runat="server"
Title="JSON WebService"
Height="500"
Width="200"
Margins="10"
Border="false">
<Store>
<ext:TreeStore runat="server">
<Proxy>
<ext:AjaxProxy Url="TreeJsonService.asmx/GetNodes" Json="true">
<ActionMethods Read="POST" />
<Reader>
<ext:JsonReader>
<CustomConfig>
<ext:ConfigItem Name="getResponseData" Value="getJsonResponseData" Mode="Raw" />
</CustomConfig>
</ext:JsonReader>
</Reader>
</ext:AjaxProxy>
</Proxy>
<Parameters>
<ext:StoreParameter Name="strParam" Value="start" />
</Parameters>
</ext:TreeStore>
</Store>
<Root>
<ext:Node NodeID="0" Text="Root" />
</Root>
</ext:TreePanel>
<ext:Button ID="btnLoad" Text="Reload" OnClientClick="#{treePanel}.store.load({params:{strParam:'end'}}) ;">
</ext:Button>
</Items>
</ext:Container>
</form>
</body>
</html>

And the code for the WebService:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace adpass.client.extnet
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class TreeJsonService : System.Web.Services.WebService
{

[WebMethod]
public string GetNodes(string strParam)
{
Ext.Net.NodeCollection nodes = new Ext.Net.NodeCollection(false);

if (!string.IsNullOrEmpty(strParam))
{
for (int i = 1; i < 6; i++)
{
Ext.Net.Node asyncNode = new Ext.Net.Node();
asyncNode.Text = strParam + "-" + i;
asyncNode.NodeID = strParam + i;
nodes.Add(asyncNode);
}

for (int i = 6; i < 11; i++)
{
Ext.Net.Node treeNode = new Ext.Net.Node();
treeNode.Text = strParam + "-" + i;
treeNode.NodeID = strParam + i;
treeNode.Leaf = true;
nodes.Add(treeNode);
}
}

return nodes.ToJson();
}
}
}

Daniil
Mar 17, 2014, 6:58 AM
Hi @chulcy,

Welcome to the Ext.NET forums!

Please use:

<ext:StoreParameter Name="strParam" Value="start" ApplyMode="IfNotExists" />

chulcy
Mar 17, 2014, 5:13 PM
Thank you very much Daniil
That worked!

Can you explain why that works, please?
Thanks!

Daniil
Mar 17, 2014, 5:36 PM
Defaults to:

ApplyMode="Always"

It means a priority. It overrides a parameter you pass to a TreeStore's load call.