PDA

View Full Version : [CLOSED] THe Gridpanel with Store can't Bind the Data via Page in DataSource using the customizing DirectMethod or DirectEvent



hujq
Jun 12, 2012, 2:27 AM
hi! Daniil (http://forums.ext.net/member.php?2345-Daniil),geoffrey.mcgill (http://forums.ext.net/member.php?2-geoffrey-mcgill),etr.
There is something wrong with that Paging and Sorting data in DataSource(SQL SERVER OR WEB SERVICES IN LINQ TO SQL) in my requirement.I copy the example code in your Example Explorer ( Version 2.0 Beta3)(the path:http://examples2.ext.net/#/GridPanel/Paging_and_Sorting/Page/),the example code use the ObjectDatasource to join the Gridpanel and Employee class.when i click the next/previous page button and the refresh button 4352 which belong to the GridPanel component,and the click action can trigger the OnReadData="Store1_RefreshData" on the Store,so the example can run well.
but now ,i want to customize my query with paging in remote datasource (not in local paging and sorting),I give up the ObjectDatasource to join the Gridpanel and Employee class.I bind the datasource to the store of GridPanel via programming. The GridPanel can display the data when i load it first,The Store's OnReadData Event can trigger when the page is loaded first. Strangely,when I click the node of tree on the west region of the Viewport component.the Store's OnReadData Event can't trigger,The gridpanel can't display the data via programming databind.Acturally There are many records in the return value,but the Gridpanel can't display the return data. Why?Please give me a example ,my Demon is flowed as:
4353



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ext.Net;
using LINQTOSQL;
using System.Text;
using System.IO;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Transactions;
using System.Linq.Expressions;
/// <summary>
///Employee 的摘要说明
/// </summary>
public class GetSystemUser
{
public GetSystemUser()
{
//
//TODO: 在此处添加构造函数逻辑
//
}


public static List<SystemUser> GetAll()
{
NEW_OA_DataClassesDataContext db = new NEW_OA_DataClassesDataContext();


return db.SystemUser.ToList();
}


public static SystemUser GetEmployee(string id)
{
NEW_OA_DataClassesDataContext db = new NEW_OA_DataClassesDataContext();


return GetEmployee(id, db);
}

public static SystemUser GetEmployee(string id, NEW_OA_DataClassesDataContext db)
{
return db.SystemUser.Single(e => e.UserId == id);
}


public class tempSystemUser
{
public string UserId { get; set; }
public string DeptId { get; set; }
public string UserName { get; set; }
}


public static List<SystemUser> GetEmployeesFilter(int start, int limit, DataSorter sort,string nodeid, out int count)
{
NEW_OA_DataClassesDataContext db = new NEW_OA_DataClassesDataContext();
IQueryable<SystemUser> result = from user in db.SystemUser
where user.DeptId==nodeid
select user;
if (sort != null)
{
var param = Expression.Parameter(typeof(SystemUser), "e");

if (sort.Property == "UserId" || sort.Property == "UserName")
{
var sortExpression = Expression.Lambda<Func<SystemUser, string>>(Expression.Property(param, sort.Property), param);
if (sort.Direction == SortDirection.DESC)
{
result = result.OrderByDescending(sortExpression);
}
else
{
result = result.OrderBy(sortExpression);
}
}
else
{
var sortExpression = Expression.Lambda<Func<SystemUser, object>>(Expression.Property(param, sort.Property), param);
if (sort.Direction == SortDirection.DESC)
{
result = result.OrderByDescending(sortExpression);
}
else
{
result = result.OrderBy(sortExpression);
}
}
}


if (start >= 0 && limit > 0)
{
result = result.Skip(start).Take(limit);
}
count =(from uu in db.SystemUser where uu.DeptId==nodeid select uu).Count();
return result.ToList();
}
}






<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AddUser.aspx.cs" Inherits="webUI_Administrator_AddUser" %>




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>GridPanel with ObjectDataSource - Ext.NET Examples</title>
<link href="/resources/css/examples.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.x-grid-cell-fullName .x-grid-cell-inner
{
font-family: tahoma, verdana;
display: block;
font-weight: normal;
font-style: normal;
color: #385F95;
white-space: normal;
}

.x-grid-rowbody div
{
margin: 2px 5px 20px 5px !important;
width: 99%;
color: Gray;
}

.x-grid-row-expanded td.x-grid-cell
{
border-bottom-width: 0px;
}
</style>
<script type="text/javascript" language="javascript">


var openWin = function (displayTag, valueTag) {
var win = App.Window6;
win.displaytag = displayTag;
win.valuetag = valueTag;
win.show();
};


var fullName = function (value, metadata, record, rowIndex, colIndex, store) {
return "<b>" + record.data.LastName + ' ' + record.data.FirstName + "</b>";
};


var nodeLoad = function (store, operation, options) {
var node = operation.node;


App.direct.NodeLoad(node.getId(), {
success: function (result) {
node.set('loading', false);
node.set('loaded', true);
var data = Ext.decode(result);
node.appendChild(data, undefined, true);
node.expand();
},


failure: function (errorMsg) {
Ext.Msg.alert('Failure', errorMsg);
}
});


return false;
};
</script>



</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
TypeName="GetSystemUser">
<SelectParameters>
<asp:Parameter Name="start" Type="Int32" />
<asp:Parameter Name="limit" Type="Int32" />
<asp:Parameter Name="sort" Type="Object" />
<asp:Parameter Name="count" Direction="Output" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<ext:Viewport ID="Viewport1" runat="server" Layout="BorderLayout">
<Items>
<ext:Panel ID="Panel2" runat="server" Title="West" Region="West" Layout="AccordionLayout"
Width="225" MinWidth="225" MaxWidth="400" Split="true" Collapsible="true">
<Items>
<ext:TreePanel ID="TreePanel1" runat="server" Title="Tree" Width="300" Height="450"
Border="false">
<Listeners>
<BeforeLoad Fn="nodeLoad" />
<ItemClick Handler="App.direct.TreeClick_SearcherUser(record.data.id);">
</ItemClick>
</Listeners>
</ext:TreePanel>
</Items>
</ext:Panel>
<ext:Panel ID="Panel1" runat="server" Title="North" Region="Center" Split="true"
Height="150" BodyPadding="6" Html="North" Collapsible="true" Layout="FitLayout">
<Items>
<ext:GridPanel runat="server" ID="GridPanel1" Title="Employees" Frame="false" Height="300">
<Store>
<ext:Store ID="Store1" runat="server" RemoteSort="true" OnReadData="Store1_RefreshData"
PageSize="5">
<AutoLoadParams>
<ext:Parameter Name="start" Value="0" Mode="Raw" />
<ext:Parameter Name="limit" Value="5" Mode="Raw" />
</AutoLoadParams>
<Proxy>
<ext:PageProxy AutoDataBind="true">
</ext:PageProxy>
</Proxy>
<Model>
<ext:Model ID="Model1" runat="server" IDProperty="UserId">
<Fields>
<ext:ModelField Name="UserId" />
<ext:ModelField Name="DeptId" />
<ext:ModelField Name="UserName" />
</Fields>
</ext:Model>
</Model>
<Sorters>
<ext:DataSorter Property="UserId" Direction="ASC" />
</Sorters>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column ID="Column2" runat="server" DataIndex="UserId" Text="Title" Width="150" />
<ext:Column ID="Column3" runat="server" DataIndex="DeptId" Text="Title Of Courtesy"
Width="150" />
<ext:Column ID="Column10" runat="server" DataIndex="UserName" Text="Extension" Width="100" />
</Columns>
</ColumnModel>
<View>
<ext:GridView ID="GridView1" runat="server">
<GetRowClass Handler="return 'x-grid-row-expanded';" />
</ext:GridView>
</View>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" runat="server" Mode="Multi" />
</SelectionModel>
<Features>
<ext:RowBody ID="RowBody1" runat="server">
<GetAdditionalData Handler="return {rowBodyColspan : record.fields.getCount(), rowBody : '<p>' + data.Notes + '</p>'};" />
</ext:RowBody>
</Features>
<BottomBar>
<ext:PagingToolbar ID="PagingToolbar1" runat="server" DisplayInfo="true" DisplayMsg="Displaying employees {0} - {1} of {2}"
EmptyMsg="No employees to display" />
</BottomBar>
<TopBar>
<ext:Toolbar ID="TopToolBars" runat="server">
<Items>
<ext:Button ID="ButtonAddUser" Text="AddNewUser" Icon="UserAdd">
<Listeners>
<Click Handler="App.WindowUserInformation.show();">
</Click>
</Listeners>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
</ext:GridPanel>
</Items>
</ext:Panel>
</Items>
</ext:Viewport>
<ext:Window ID="Window6" runat="server" Icon="House" Title="ASP.NET Button with Custom Listener"
Hidden="true" Width="500" Height="500">
<Loader Url="../PubTree/MenuPanel1.aspx" runat="server" Mode="Frame">
</Loader>
</ext:Window>
<ext:Window ID="WindowUserInformation" runat="server" Icon="House" Title="用户基本信息"
Hidden="true" Width="600" Height="600">
<Items>
<ext:FormPanel ID="FormPanel1" runat="server" Region="Center"
BodyPadding="5" ButtonAlign="Right" Layout="Column">
<Items>
<ext:Panel ID="Panel3" runat="server" Border="false" Header="false" ColumnWidth=".5"
Layout="Form" LabelAlign="Top">
<Defaults>
<ext:Parameter Name="AllowBlank" Value="false" Mode="Raw" />
<ext:Parameter Name="MsgTarget" Value="side" />
</Defaults>
<Items>
<ext:TextField ID="TextField_UserID" runat="server" FieldLabel="用户代码" AnchorHorizontal="92%" />
<ext:ComboBox ID="ComboBox_PostCode" runat="server" FieldLabel="职务级别"
DisplayField="PostName" ValueField="PostCode" AnchorHorizontal="95%">
<Store>
<ext:Store ID="StoreComboBoxPostCode" runat="server">
<Model>
<ext:Model ID="Model2" runat="server">
<Fields>
<ext:ModelField Name="DeptName" />
<ext:ModelField Name="DeptDm" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>
</Items>
</ext:Panel>
<ext:Panel ID="Panel4" runat="server" Border="false" Layout="Form" ColumnWidth=".5"
LabelAlign="Top">
<Defaults>
<ext:Parameter Name="AllowBlank" Value="false" Mode="Raw" />
<ext:Parameter Name="MsgTarget" Value="side" />
</Defaults>
<Items>
<ext:TextField ID="TextField_UserName" runat="server" FieldLabel="用户名" AnchorHorizontal="92%" />

<ext:DateField ID="DateFieldBirthday" runat="server" FieldLabel="生日" AnchorHorizontal="92%" />
</Items>
</ext:Panel>
<ext:Panel ID="Panel5" runat="server" Border="false" Header="false" ColumnWidth=".5"
Layout="Form" LabelAlign="Top">
<Defaults>
<ext:Parameter Name="AllowBlank" Value="false" Mode="Raw" />
<ext:Parameter Name="MsgTarget" Value="side" />
</Defaults>
<Items>
<ext:TextField ID="TextFieldOfficePhone" runat="server" FieldLabel="办公电话" AnchorHorizontal="92%" />
<ext:TextField ID="TextFieldMobilePhone" runat="server" FieldLabel="移动电话" AnchorHorizontal="92%" />
</Items>
</ext:Panel>
<ext:Panel ID="Panel6" runat="server" Border="false" Layout="Form" ColumnWidth=".5"
LabelAlign="Top">
<Defaults>
<ext:Parameter Name="AllowBlank" Value="false" Mode="Raw" />
<ext:Parameter Name="MsgTarget" Value="side" />
</Defaults>
<Items>
<ext:TextField ID="TextFieldEmail" runat="server" FieldLabel="电子邮箱" Vtype="email" AnchorHorizontal="92%" />
<ext:TextField ID="TextFieldOfficeNO" runat="server" FieldLabel="办公室房号" AnchorHorizontal="92%" />
</Items>
</ext:Panel>
</Items>
<BottomBar>
<ext:StatusBar ID="StatusBar1" runat="server" />
</BottomBar>
<Listeners>
<ValidityChange Handler="this.dockedItems.get(1).setStatus({
text : valid ? 'Form is valid' : 'Form is invalid',
iconCls: valid ? 'icon-accept' : 'icon-exclamation'
});
#{Button1}.setDisabled(!valid);" />
</Listeners>

</ext:FormPanel>
</Items>
<Buttons>
<ext:Button ID="ButtonSave" runat="server" Text="Save" Disabled="true" FormBind="true">
<Listeners>
<Click Handler="if (#{FormPanel1}.getForm().isValid()) {Ext.Msg.alert('Submit', 'Saved!');}else{Ext.Msg.show({icon: Ext.MessageBox.ERROR, msg: 'FormPanel is incorrect', buttons:Ext.Msg.OK});}" />
</Listeners>
</ext:Button>
<ext:Button ID="ButtonCancel" runat="server" Text="Cancel" >
<Listeners>
<Click Handler="#{FormPanel1}.getForm().reset();" />
</Listeners>
</ext:Button>
</Buttons>
</ext:Window>
<ext:Hidden ID="Hidden_Value" runat="server">
</ext:Hidden>
<%-- <Items>
<ext:TriggerField
ID="TriggerField_Text"
runat="server"
Width="200"
Editable="false">
<Triggers>
<ext:FieldTrigger Icon="Search" Qtip="Click to choose value" />
</Triggers>
<Listeners>
<TriggerClick Handler="openWin(#{TriggerField_Text},#{Hidden_Value});" />
</Listeners>
</ext:TriggerField>
</Items>--%>
</form>
</body>
</html>







using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using LINQTOSQL;
using Ext.Net.Utilities;
using Ext.Net.Examples;
using Ext.Net.MVC;




public partial class webUI_Administrator_AddUser : System.Web.UI.Page
{



NEW_OA_DataClassesDataContext noa = new NEW_OA_DataClassesDataContext();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack && !X.IsAjaxRequest)
{
var dep = noa.Deptment.FirstOrDefault(p => p.Dep_DeptId == null);
Node nd = new Node();
nd.NodeID = dep.DeptId;
nd.Text = dep.DeptName;
TreePanel1.Root.Add(nd);
}
}

private StoreReadDataEventArgs e;
protected void Store1_RefreshData(object sender, StoreReadDataEventArgs e)
{


e.Total = SearchUser(Convert.ToInt16(e.Start), Convert.ToInt16(e.Limit), e.Sort[0], "Q9OBM1OKJAF");

}


[DirectMethod]
public void TreeClick_SearcherUser(string nodeid)
{
int limit= Convert.ToInt16(this.Store1.AutoLoadParams.GetPara meter("limit").Value);
int start = Convert.ToInt16(this.Store1.AutoLoadParams.GetPara meter("start").Value);
DataSorter ds = this.Store1.Sorters.SingleOrDefault();
(this.Store1.Proxy[0] as PageProxy).Total= SearchUser(start,limit,ds,nodeid);
}

protected int SearchUser(int start,int limit,DataSorter ds,string nodeid)
{
int a = 0;
this.Store1.DataSource = GetSystemUser.GetEmployeesFilter(start, limit, ds,nodeid, out a);
this.Store1.DataBind();
//(this.Store1.Proxy[0] as PageProxy).Total = a;
return a;
}


[DirectMethod]
public static string NodeLoad(string nodeID)
{



NEW_OA_DataClassesDataContext nad = new NEW_OA_DataClassesDataContext();
NodeCollection nodes = new NodeCollection();
if (nad.Deptment.FirstOrDefault(p => p.DeptId == nodeID).Dep_DeptId == null)
{
int dep = (from de in nad.Deptment where de.Dep_DeptId == null select de.Dep_DeptId).Count();
if (dep == 1)
{
var topDept = from dd in nad.Deptment
where dd.Dep_DeptId == null
select new { detpID = dd.DeptId, deptName = dd.DeptName };
if (topDept.Count() > 0)
{


var secDept = from sec in nad.Deptment
where sec.Dep_DeptId == topDept.FirstOrDefault().detpID
select new { secNewId = sec.DeptId, secNewName = sec.DeptName,isLeaf=sec.IsLeaf };
// NodeCollection nodes1 = new NodeCollection();
foreach (var sd in secDept)
{
if (sd.isLeaf != true)
{
Node asyncNode = new Node();
asyncNode.Text = sd.secNewName;
asyncNode.NodeID = sd.secNewId;
nodes.Add(asyncNode);
}
else
{
Node treeNode = new Node();
treeNode.Text = sd.secNewName;
treeNode.NodeID =sd.secNewId;
treeNode.Leaf = true;
nodes.Add(treeNode);
}
}
return nodes.ToJson();
}
}
}
else
{
var subDepts = from subDept in nad.Deptment
where subDept.Dep_DeptId == nodeID
select new { detpID = subDept.DeptId, deptName = subDept.DeptName,isLeaf=subDept.IsLeaf };
//NodeCollection nodes2 = new NodeCollection();
foreach (var sd in subDepts)
{
if (sd.isLeaf != true)
{
Node asyncNode = new Node();
asyncNode.Text = sd.deptName;
asyncNode.NodeID = sd.detpID;
nodes.Add(asyncNode);
}
else
{
Node treeNode = new Node();
treeNode.Text =sd.deptName;
treeNode.NodeID = sd.detpID;
treeNode.Icon = Icon.User;
treeNode.Leaf = true;
nodes.Add(treeNode);
}
}
return nodes.ToJson();
}
return nodes.ToJson();

}
}


the database's table structure:

4354

Daniil
Jun 12, 2012, 10:34 AM
Hi,

Well, it is not enough to set up just Total property within the OnReadData handler.

Please investigate the example how to organize remote paging and sorting using PageProxy.
http://examples2.ext.net/#/GridPanel/Paging_and_Sorting/Page/