I am using telerik radgrid and want to perform server side paging. I am refreing to this demo by telerik.
Here is the code that shows how my grid is configured to handle this.
<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" />
and here is my code which provides data to 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;
}
Here custom paging is working fine. but filter and sorting is not working. Can anyone point out what am i doing wrong here ?
If you are going to use custom paging with filtering and sorting, you need to disable the custom paging when there are filters (or sort expressions) applied and you need to provide the entire data set to RadGrid's DataSource, so it could apply its internal paging functionality as in the demo that you are referring to.