我正在使用telerik radgrid并希望执行服务器端分页。我正在通过telerik对this demo进行反思。
以下是显示我的网格配置如何处理此问题的代码。
<telerik:RadGrid ID="radGridMyWorksheet" AllowMultiColumnSorting="true" runat="server" AutoGenerateColumns="false" ShowStatusBar="True"
AllowSorting="True" ClientSettings-Scrolling-EnableVirtualScrollPaging="false"
ClientSettings-Scrolling-AllowScroll="false" AllowCustomPaging="true"
OnNeedDataSource="radGridMyWorksheet_NeedDataSource" AllowFilteringByColumn="True" OnGroupsChanging="radGridMyWorksheet_GroupsChanging"
EnableLinqExpressions="false"
OnItemDataBound="radGridMyWorksheety_ItemDataBound" OnInsertCommand="radGridMyWorksheet_InsertCommand">
<MasterTableView DataKeyNames="ID" AllowMultiColumnSorting="true"
Width="100%" CommandItemDisplay="Top" Name="radGridMyWorksheet" AllowPaging="true">
<AlternatingItemStyle BackColor="WhiteSmoke" />
这是我的代码,它为gridview提供数据。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
radGridMyWorksheet.VirtualItemCount = calling method that returns total record count
}
}
protected void radGridMyWorksheet_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
try
{
List<Expression<Func<RouteWorksheet, object>>> include = new List<Expression<Func<RouteWorksheet, object>>>();
Expression<Func<RouteWorksheet, object>> routeInclude = (route) => route.Route;
include.Add(routeInclude);
int CurrentPageIndex = radGridMyWorksheet.CurrentPageIndex == 0 ? 1 : radGridMyWorksheet.CurrentPageIndex;
int startRowIndex = (ShouldApplySortFilterOrGroup()) ?
1 : CurrentPageIndex * radGridMyWorksheet.PageSize;
int maximumRows = (ShouldApplySortFilterOrGroup()) ?
radGridMyWorksheet.VirtualItemCount : radGridMyWorksheet.PageSize;
radGridMyWorksheet.AllowCustomPaging = !ShouldApplySortFilterOrGroup();
var routeWorksheet = Repository<RouteWorksheet>.GetEntityListForQuery(r => routeIDs.Contains(r.RouteID) && r.IsDeleted == false
, x => x.OrderByDescending(y => y.RouteDate), include,
startRowIndex, maximumRows);
radGridMyWorksheet.DataSource = routeWorksheet;
}
catch (Exception ex)
{
Utility.WalkException(this.Master, ex, "There was an error while processing the myworksheets record.");
}
}
public bool ShouldApplySortFilterOrGroup()
{
return radGridMyWorksheet.MasterTableView.FilterExpression != "" ||
(radGridMyWorksheet.MasterTableView.GroupByExpressions.Count > 0 || isGrouping) ||
radGridMyWorksheet.MasterTableView.SortExpressions.Count > 0;
}
这里自定义分页工作正常。但过滤和排序不起作用。谁能指出我在这里做错了什么?
答案 0 :(得分:0)
如果要使用带有过滤和排序的自定义分页,则需要在应用过滤器(或排序表达式)时禁用自定义分页,并且需要将整个数据集提供给RadGrid的DataSource,以便它可以应用它的内部分页功能,如您所指的演示。
答案 1 :(得分:0)
Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As GridNeedDataSourceEventArgs) 'Handles RadGrid1.NeedDataSource
Dim RadGrid1 As RadGrid = CType(Page.Master.FindControl("ContentPlaceHolder1").FindControl("RadGrid1"), RadGrid)
Dim gridSortString As String = RadGrid1.MasterTableView.SortExpressions.GetSortString()
Dim args As New DataSourceSelectArguments(gridSortString)
If gridSortString Is Nothing Then
RadGrid1.DataSource = GetDataTable("SELECT کالا.شناسه, کالا.عنوان, کالا.پوشه, بارگیری, کالا.گروه_شناسه, گروه.عنوان AS گروه FROM کالا LEFT JOIN گروه ON کالا.گروه_شناسه = گروه.شناسه")
Else
RadGrid1.DataSource = GetDataTable("SELECT کالا.شناسه, کالا.عنوان, کالا.پوشه, بارگیری, کالا.گروه_شناسه, گروه.عنوان AS گروه FROM کالا LEFT JOIN گروه ON کالا.گروه_شناسه = گروه.شناسه ORDER BY " & gridSortString)
End If
End Sub