PDA

View Full Version : [OPEN] [#265] how to reload AjaxProxy?



hdsoso
Jun 03, 2013, 3:05 PM
when update treegrid , then how to reload AjaxProxy?


<ext:TreePanel runat="server" ID="menu_tp" RootVisible="true">
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="保存" Icon="Disk">
<DirectEvents>

<Click OnEvent="SaveClick" >
<ExtraParams>
<ext:Parameter Name="data" Value="#{menu_store}.getChangedData()" Mode="Raw" Encode="true" />
</ExtraParams>

</Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>

</TopBar>
<Store>
<ext:TreeStore runat="server" ID="menu_store">
<Root>
<ext:Node Text="根菜单" Expanded="True">
<CustomAttributes>
<ext:ConfigItem Name="id" Value="-1" runat="server" />
<ext:ConfigItem Name="name" Value="根菜单" runat="server" />
<ext:ConfigItem Name="pid" Value="-1" runat="server" />
<ext:ConfigItem Name="url" Value="" runat="server" />
</CustomAttributes>

</ext:Node>

</Root>
<Proxy>
<ext:AjaxProxy Url="../handlers/Handler_menu1.ashx">
</ext:AjaxProxy>
</Proxy>
<Model>
<ext:Model runat="server" IDProperty="id">
<Fields>
<ext:ModelField runat="server" Name="id"></ext:ModelField>
<ext:ModelField runat="server" Name="name"></ext:ModelField>
<ext:ModelField runat="server" Name="pid"></ext:ModelField>
<ext:ModelField runat="server" Name="url"></ext:ModelField>
</Fields>
</ext:Model>
</Model>
</ext:TreeStore>
</Store>
<ColumnModel>
<Columns>
<ext:Column runat="server" Text="编号" DataIndex="id"></ext:Column>
<ext:TreeColumn runat="server" Text="名称" DataIndex="name" Flex="1">
<Editor>
<ext:TextField runat="server"></ext:TextField>
</Editor>
</ext:TreeColumn>
<ext:Column runat="server" Text="url" DataIndex="url" Flex="1">
<Editor>
<ext:TextField ID="TextField1" runat="server"></ext:TextField>
</Editor>
</ext:Column>
</Columns>
</ColumnModel>
<Plugins>
<ext:CellEditing runat="server"></ext:CellEditing>
</Plugins>
</ext:TreePanel>



protected void SaveClick(object sender, DirectEventArgs e)
{

ChangeRecords<ExtDemoEf.menu> menues = new StoreDataHandler(e.ExtraParams["data"]).BatchObjectData<ExtDemoEf.menu>();
foreach (ExtDemoEf.menu created in menues.Created)
{
}
foreach (ExtDemoEf.menu deleted in menues.Deleted)
{
}
foreach (ExtDemoEf.menu updated in menues.Updated)
{
menuService.Update(updated);
}
//how to reload store
}

Daniil
Jun 03, 2013, 3:50 PM
Hi @hdsoso,

Please try:

tree.getStore().reload();

ViDom
Jun 03, 2013, 4:33 PM
Hi @hdsoso,

Please try:

tree.getStore().reload();


In code behind it should be in this case:


Ext.Net.X.Js.AddScript(this.menu_tp.ClientID+".getStore().reload();");

hdsoso
Jun 03, 2013, 11:15 PM
In code behind it should be in this case:


Ext.Net.X.Js.AddScript(this.menu_tp.ClientID+".getStore().reload();");


after reload, there is no leaf node
plz see screen capture.
http://screencast.com/t/lp8ya6zNB

Baidaly
Jun 03, 2013, 11:30 PM
Hello!

I think you send back to the client wrong nodes collection. Please, double check you send all data to the client on reload.

hdsoso
Jun 03, 2013, 11:45 PM
Hello!

I think you send back to the client wrong nodes collection. Please, double check you send all data to the client on reload.

I think data of nodes collection is ok,becuase reopen the tab, the tree is ok through the screen capture.
ashx code is


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ExtDemoEf;
using System.Text;

namespace extdemo.handlers
{
/// <summary>
/// Handler_menu1 的摘要说明
/// </summary>
public class Handler_menu1 : IHttpHandler
{

MenuService menusrv = new MenuService();
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/json";

string json = buildjson(0, null);
string str = "[" + json.Substring(0, json.Length - 1) + "]";

context.Response.Write(str);
context.Response.End();
}
public string buildjson(int pid, StringBuilder sb)
{
List<menu> ll = menusrv.getMenuList(pid);
int n = ll.Count;
int i = 0;
foreach (var item in ll)
{

menu sm = item;
if (sb == null)
{
sb = new StringBuilder();
}
sb.Append("{");
sb.Append("'id':'" + sm.id + "',");
sb.Append("'name':'" + sm.name + "',");
sb.Append("'pid':'" + sm.pid + "',");
sb.Append("'url':'" + sm.url + "'");
if (!menusrv.isLeaf(sm.id))
{
sb.Append(",");
sb.Append("'expanded': true,");
sb.Append("children:[");
buildjson(sm.id, sb);
sb.Append("]");
sb.Append("},");

}
else
{
i = i + 1;
sb.Append(",'leaf':true");
if (i != n)
{
sb.Append("},");
}
else
{
sb.Append("}");
}
}
}

return sb.ToString();
}

public bool IsReusable
{
get
{
return false;
}
}
}
}

the str sample data is


[{'id':'1','name':'客户关系系统','pid':'0','url':'','expa nded': true,children:[{'id':'2','name':'客户管理22222555','pid':'1','url':'p ages/customer.aspx','leaf':true},{'id':'7','name':'客户回收 站1111555','pid':'1','url':'pages/customer_hsz.aspx','leaf':true}]},{'id':'8','name':'常用工具','pid':'0','url':'','expa nded': true,children:[{'id':'9','name':'rss采集33344','pid':'8','url':'pag es/rss.aspx','leaf':true}]},{'id':'11','name':'用户管理555555','pid':'0','url':' ','expanded': true,children:[{'id':'12','name':'修改密码','pid':'11','url':'pages/passreset.aspx','leaf':true}]},{'id':'13','name':'权限管理','pid':'0','url':'','exp anded': true,children:[{'id':'14','name':'角色菜单分配122222','pid':'13','url': 'pages/role_menu.aspx','leaf':true},{'id':'15','name':'用户 角色分配122222','pid':'13','url':'pages/user_role.aspx','leaf':true},{'id':'16','name':'角色 管理','pid':'13','url':'pages/role.aspx','leaf':true},{'id':'17','name':'菜单管理',' pid':'13','url':'pages/menu.aspx','leaf':true}]}]

Baidaly
Jun 04, 2013, 1:41 AM
Try to add listener to the TreeStore:



<ext:TreeStore runat="server" ID="menu_store" >
<Root>
<ext:Node Text="???" Expanded="True">
<CustomAttributes>
<ext:ConfigItem Name="id" Value="-1" runat="server" />
<ext:ConfigItem Name="name" Value="???" runat="server" />
<ext:ConfigItem Name="pid" Value="-1" runat="server" />
<ext:ConfigItem Name="url" Value="" runat="server" />
</CustomAttributes>

</ext:Node>

</Root>
<Proxy>
<ext:AjaxProxy Url="TreeLoader.ashx" Json="True">
</ext:AjaxProxy>
</Proxy>
<Model>
<ext:Model runat="server" IDProperty="id">
<Fields>
<ext:ModelField runat="server" Name="id"></ext:ModelField>
<ext:ModelField runat="server" Name="name"></ext:ModelField>
<ext:ModelField runat="server" Name="pid"></ext:ModelField>
<ext:ModelField runat="server" Name="url"></ext:ModelField>
</Fields>
</ext:Model>
</Model>
<Listeners>
<Load Handler="#{menu_tp}.view.refresh();"></Load>
</Listeners>
</ext:TreeStore>

Daniil
Jun 04, 2013, 6:36 AM
Confirm, a refresh call help. It might be better to call it withing a callback.


App.menu_tp.getStore().reload({
callback: function () {
App.menu_tp.view.refresh();
}
})

Though. obviously a refresh call should not be required. I think it is a bug, reported here:
http://www.sencha.com/forum/showthread.php?265134

Daniil
Jun 05, 2013, 4:33 AM
Sencha opened a bug. We created an Issue to monitor.
https://github.com/extnet/Ext.NET/issues/265