Ext.net 中GridPanel或PagingToolbar能实现服务器端分页吗?也就是存储过程分页。
展开全部
当然可以了,请参考以下代码:
页面
<ext:Store ID="dsMaterial" runat="server" RemoteSort="true">
<Proxy>
//同服务端交互
<ext:HttpProxy Url="/Data/GetMaterials/" />
</Proxy>
<Reader>
<ext:JsonReader IDProperty="Identifier" Root="data" TotalProperty="total">
<Fields>迅和敏
<ext:RecordField Name="Identifier" /亩枝>
<ext:RecordField Name="Name" SortDir="ASC" />
</Fields>
</ext:JsonReader>
</Reader>
<BaseParams>
//分页所需的参数
<ext:Parameter Name="limit" Value="30" Mode="Raw" />
<ext:Parameter Name="start" Value="0" Mode="Raw" />
<ext:Parameter Name="dir" Value="ASC" />
<ext:Parameter Name="sort" Value="Name" />
</BaseParams>
<SortInfo Field="Name" Direction="ASC" />
<棚备/ext:Store>
<ext:GridPanel ID="System_Material_GridPanel" runat="server" Border="false" TrackMouseOver="true"
AutoExpandColumn="Description" ColumnLines="true" MinColumnWidth="50" StripeRows="true"
StoreID="dsMaterial">
<ColumnModel ID="System_Material_ColumnModel" runat="server">
<Columns>
<ext:Column ColumnID="Name" DataIndex="Name" Header="名称"">
</ext:Column>
</Columns>
</ColumnModel>
<SelectionModel>
<ext:CheckboxSelectionModel runat="server" RegisterAllResources="true" AllowDeselect="true"
Width="22" />
</SelectionModel>
<BottomBar>
<ext:PagingToolbar ID="System_MaterialList_PagingToolbar" runat="server" PageSize="30">
<Items>
<ext:ToolbarSeparator runat="server" Width="5" />
<ext:Label runat="server" Text="每页表示件数:" />
<ext:ToolbarSpacer runat="server" Width="5" />
<ext:ComboBox ID="PageSize_ComboBox" runat="server" Width="50">
<Items>
<ext:ListItem Text="15" />
<ext:ListItem Text="20" />
<ext:ListItem Text="30" />
<ext:ListItem Text="50" />
</Items>
<SelectedItem Value="30" />
<Listeners>
<Select Handler="#{System_MaterialList_PagingToolbar}.pageSize = parseInt(this.getValue()); #{System_MaterialList_PagingToolbar}.doLoad();" />
</Listeners>
</ext:ComboBox>
</Items>
</ext:PagingToolbar>
</BottomBar>
</ext:GridPanel>
服务器端代码(我的服务端用的Linq,代码实现有些不一样,但是请注意参数):
public AjaxStoreResult GetMaterials(int limit, int start, string dir, string sort)
{
var query = (from material in this.DBContext.Tbl_Material
select new
{
material.Identifier,
material.Name
}).OrderBy(string.Concat(sort, " ", dir));
int total = query.ToList().Count;
query = query.Skip(start).Take(limit);
return new AjaxStoreResult(query, total);
}
页面
<ext:Store ID="dsMaterial" runat="server" RemoteSort="true">
<Proxy>
//同服务端交互
<ext:HttpProxy Url="/Data/GetMaterials/" />
</Proxy>
<Reader>
<ext:JsonReader IDProperty="Identifier" Root="data" TotalProperty="total">
<Fields>迅和敏
<ext:RecordField Name="Identifier" /亩枝>
<ext:RecordField Name="Name" SortDir="ASC" />
</Fields>
</ext:JsonReader>
</Reader>
<BaseParams>
//分页所需的参数
<ext:Parameter Name="limit" Value="30" Mode="Raw" />
<ext:Parameter Name="start" Value="0" Mode="Raw" />
<ext:Parameter Name="dir" Value="ASC" />
<ext:Parameter Name="sort" Value="Name" />
</BaseParams>
<SortInfo Field="Name" Direction="ASC" />
<棚备/ext:Store>
<ext:GridPanel ID="System_Material_GridPanel" runat="server" Border="false" TrackMouseOver="true"
AutoExpandColumn="Description" ColumnLines="true" MinColumnWidth="50" StripeRows="true"
StoreID="dsMaterial">
<ColumnModel ID="System_Material_ColumnModel" runat="server">
<Columns>
<ext:Column ColumnID="Name" DataIndex="Name" Header="名称"">
</ext:Column>
</Columns>
</ColumnModel>
<SelectionModel>
<ext:CheckboxSelectionModel runat="server" RegisterAllResources="true" AllowDeselect="true"
Width="22" />
</SelectionModel>
<BottomBar>
<ext:PagingToolbar ID="System_MaterialList_PagingToolbar" runat="server" PageSize="30">
<Items>
<ext:ToolbarSeparator runat="server" Width="5" />
<ext:Label runat="server" Text="每页表示件数:" />
<ext:ToolbarSpacer runat="server" Width="5" />
<ext:ComboBox ID="PageSize_ComboBox" runat="server" Width="50">
<Items>
<ext:ListItem Text="15" />
<ext:ListItem Text="20" />
<ext:ListItem Text="30" />
<ext:ListItem Text="50" />
</Items>
<SelectedItem Value="30" />
<Listeners>
<Select Handler="#{System_MaterialList_PagingToolbar}.pageSize = parseInt(this.getValue()); #{System_MaterialList_PagingToolbar}.doLoad();" />
</Listeners>
</ext:ComboBox>
</Items>
</ext:PagingToolbar>
</BottomBar>
</ext:GridPanel>
服务器端代码(我的服务端用的Linq,代码实现有些不一样,但是请注意参数):
public AjaxStoreResult GetMaterials(int limit, int start, string dir, string sort)
{
var query = (from material in this.DBContext.Tbl_Material
select new
{
material.Identifier,
material.Name
}).OrderBy(string.Concat(sort, " ", dir));
int total = query.ToList().Count;
query = query.Skip(start).Take(limit);
return new AjaxStoreResult(query, total);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可以的,得修改一下编程
追问
晕!能详细点吗?
追答
那就不那么简单了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
eryfgddsasbnshg
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
dghgfhtfbhtrtrtry
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
dhtegthyergsxgft
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询