Hi,
I'm looking for a very urgent clarification about the concurrency of CustomPaging and FilteringByColumn used together in a RadGrid.
I always have as a datasource a function that returns a DataTable considering both Filtering and Paging. This is necessary since the amount of datas is very significative and cannot return the whole amount of datas to the RadGrid and the Page it, but I have to return only the needed records and only in small paged size (50 records).
The approach I've used up to now is as illustrated here:
Default.aspx
Default.aspx.vb
This works fine, but if I use Filtering then Paging gets disabled ! Now I need to use both together so my approach in the code behind has simply changed this way:
The only thing changed is the approach in retrieving the startIndex and the pageSize that now works the same way either if I'm filtering or not.
My point is: this thing seems to work, but I have to deliver it very soon and since I have not found posts of this approach anywhere I'm wondering if I'm missing something important that this approach does not consider.
If anybody finds reasonable reasons why this should fail in some circumstances please let me know.
Thanks in advance.
Lorenzo
I'm looking for a very urgent clarification about the concurrency of CustomPaging and FilteringByColumn used together in a RadGrid.
I always have as a datasource a function that returns a DataTable considering both Filtering and Paging. This is necessary since the amount of datas is very significative and cannot return the whole amount of datas to the RadGrid and the Page it, but I have to return only the needed records and only in small paged size (50 records).
The approach I've used up to now is as illustrated here:
Default.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!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
></
title
>
<
telerik:RadStyleSheetManager
id
=
"RadStyleSheetManager1"
runat
=
"server"
/>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
>
<
Scripts
>
<%--Needed for JavaScript IntelliSense in VS2010--%>
<%--For VS2008 replace RadScriptManager with ScriptManager--%>
<
asp:ScriptReference
Assembly
=
"Telerik.Web.UI"
Name
=
"Telerik.Web.UI.Common.Core.js"
/>
<
asp:ScriptReference
Assembly
=
"Telerik.Web.UI"
Name
=
"Telerik.Web.UI.Common.jQuery.js"
/>
<
asp:ScriptReference
Assembly
=
"Telerik.Web.UI"
Name
=
"Telerik.Web.UI.Common.jQueryInclude.js"
/>
</
Scripts
>
</
telerik:RadScriptManager
>
<
script
type
=
"text/javascript"
>
//Put your JavaScript code here.
</
script
>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
</
telerik:RadAjaxManager
>
<
div
>
<
telerik:RadGrid
runat
=
"server"
ID
=
"RadGrid"
AutoGenerateColumns
=
"false"
AllowCustomPaging
=
"true"
AllowPaging
=
"true"
PageSize
=
"50"
AllowFilteringByColumn
=
"true"
EnableLinqExpressions
=
"false"
>
<
GroupingSettings
CaseSensitive
=
"False"
/>
<
ClientSettings
>
<
Selecting
AllowRowSelect
=
"True"
/>
<
Scrolling
AllowScroll
=
"True"
ScrollHeight
=
"100%"
UseStaticHeaders
=
"True"
/>
</
ClientSettings
>
<
PagerStyle
AlwaysVisible
=
"True"
/>
<
MasterTableView
OverrideDataSourceControlSorting
=
"True"
>
<
NoRecordsTemplate
>
</
NoRecordsTemplate
>
<
Columns
>
<%--Some columns here--%>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
div
>
</
form
>
</
body
>
</
html
>
Default.aspx.vb
Imports Telerik.Web.UI
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub RadGrid_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid.NeedDataSource
Dim VirtualItemCount As Integer = GetDatasVirtualItemsCount(RadGrid.MasterTableView.FilterExpression)
RadGrid.MasterTableView.VirtualItemCount = VirtualItemCount
RadGrid.VirtualItemCount = VirtualItemCount
Dim startIndex As Integer = IIf((ShouldApplySortFilterOrGroup()), 0, RadGrid.CurrentPageIndex * RadGrid.PageSize)
Dim pageSize As Integer = IIf((ShouldApplySortFilterOrGroup()), VirtualItemCount, RadGrid.PageSize)
RadGrid.DataSource = GetDatas(startIndex, pageSize, RadGrid.MasterTableView.FilterExpression)
End Sub
Private isGrouping As Boolean = False
Protected Sub RadGrid1_GroupsChanging(ByVal source As Object, ByVal e As GridGroupsChangingEventArgs)
isGrouping = True
If e.Action = GridGroupsChangingAction.Ungroup AndAlso RadGrid.CurrentPageIndex > 0 Then
isGrouping = False
End If
End Sub
Public Function ShouldApplySortFilterOrGroup() As Boolean
Return RadGrid.MasterTableView.FilterExpression <> "" _
OrElse (RadGrid.MasterTableView.GroupByExpressions.Count > 0 OrElse isGrouping) OrElse RadGrid.MasterTableView.SortExpressions.Count > 0
End Function
Private Function GetDatas(ByVal startIndex As Integer, ByVal pageSize As Integer, ByVal FilterExpression As String) As DataTable
' ------------
' Some Code that generates a datatable considering both CustomPaging and Filtering
' ------------
Return New DataTable
End Function
Private Function GetDatasVirtualItemsCount(ByVal FilterExpression As String) As Integer
' ------------
' Some Code that count the number of rows considering Filtering
' ------------
Return -1
End Function
End Class
This works fine, but if I use Filtering then Paging gets disabled ! Now I need to use both together so my approach in the code behind has simply changed this way:
Imports Telerik.Web.UI
Imports System.Data
Partial Class _Default2
Inherits System.Web.UI.Page
Protected Sub RadGrid_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid.NeedDataSource
Dim VirtualItemCount As Integer = GetDatasVirtualItemsCount(RadGrid.MasterTableView.FilterExpression)
RadGrid.MasterTableView.VirtualItemCount = VirtualItemCount
RadGrid.VirtualItemCount = VirtualItemCount
Dim startIndex As Integer = RadGrid.CurrentPageIndex * RadGrid.PageSize
Dim pageSize As Integer = RadGrid.PageSize
RadGrid.DataSource = GetDatas(startIndex, pageSize, RadGrid.MasterTableView.FilterExpression)
End Sub
Private Function GetDatas(ByVal startIndex As Integer, ByVal pageSize As Integer, ByVal FilterExpression As String) As DataTable
' ------------
' Some Code that generates a datatable considering both CustomPaging and Filtering
' ------------
Return New DataTable
End Function
Private Function GetDatasVirtualItemsCount(ByVal FilterExpression As String) As Integer
' ------------
' Some Code that count the number of rows considering Filtering
' ------------
Return -1
End Function
End Class
The only thing changed is the approach in retrieving the startIndex and the pageSize that now works the same way either if I'm filtering or not.
My point is: this thing seems to work, but I have to deliver it very soon and since I have not found posts of this approach anywhere I'm wondering if I'm missing something important that this approach does not consider.
If anybody finds reasonable reasons why this should fail in some circumstances please let me know.
Thanks in advance.
Lorenzo