Telerik RadGrid自定义分页过滤器和排序不工作
本文关键字:排序 工作 过滤器 RadGrid 自定义 分页 Telerik | 更新日期: 2023-09-27 17:54:12
我正在使用telerik radgrid,并希望执行服务器端分页。我指的是teleerik的这个演示。
下面的代码显示了如何配置我的网格来处理这个
<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;
}
这里自定义分页工作得很好。但是过滤和排序不起作用。谁能指出我在这里做错了什么?
如果你打算使用自定义分页过滤和排序,你需要禁用自定义分页,当有过滤器(或排序表达式)应用,你需要提供整个数据集到RadGrid的数据源,所以它可以应用它的内部分页功能,正如你所引用的演示
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