This is a migrated thread and some comments may be shown as answers.

RadGrid filtering and paging not working properly together

4 Answers 453 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stephan
Top achievements
Rank 1
Stephan asked on 29 Mar 2011, 11:07 AM
Hi, i got this problem. In my grid I can filter on some columns. This is working fine, however when I filter footer of the grid keeps showing the paging despite the fact that the filtering results in less items than configured in the RadGrid (15 items).

For binding the data to the grid I use the Needdatasource-event. In this event I also have some filtering based on previous set session-value.

So filtering does working. But it should not show the paging when I have less than 15 items. Also when paging is shown, it looks like it is still based on the whole dataset. Not the filterd dataset.

When I don't use filtering, paging is working fine.

The filtering set in the needdatasource event is independent from the filtering in the radgrid -filteritems itself.

What am I missing.

Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
       Dim dtTaxatie As DataTable = (New RisicoTaxatieManager()).GetTaxatieOverzicht()
 
       Dim filterExpression As String = String.Empty
       Dim columnIdent As String = String.Empty
       Dim row As RisicoTaxatie.libPatientRow = Nothing
 
       If (Not Page.IsPostBack) Then
           If Not Session("PatientRow") Is Nothing Then
               row = DirectCast(Session("PatientRow"), RisicoTaxatie.libPatientRow)
               If Not String.IsNullOrEmpty(AppConfig.FilterColumn) Then
                   Select Case AppConfig.FilterColumn
                       Case "MITS"
                           filterExpression = IIf(Not row.IsMitsnummerNull(), "(Mitsnummer='" + row.Mitsnummer.ToString().Trim() + "')", String.Empty)
                       Case "BSN"
                           filterExpression = IIf(Not row.IsBSNnummerNull(), "(BSNnummer='" + row.BSNnummer.ToString().Trim() + "')", String.Empty)
                       Case "VIP"
                           filterExpression = IIf(Not row.IsVIPnummerNull(), "(VIPnummer='" + row.VIPnummer.ToString().Trim() + "')", String.Empty)
                   End Select
               End If
 
           End If
       End If
 
       If AppConfig.FilterPatienten And String.IsNullOrEmpty(filterExpression) Then
           Dim dtPatienten As DataView = (New RisicoTaxatieManager()).GetMedewerkerPatienten(MedewerkerId)
           dtPatienten.RowFilter = "Gekoppeld=1"
           Dim filterPatientId As String = String.Empty
           For Each PatientRow As DataRowView In dtPatienten
               filterPatientId += PatientRow("Id").ToString() + ","
           Next
 
           If Not String.IsNullOrEmpty(filterPatientId) Then
               filterExpression = String.Format("PatientId IN ({0})", filterPatientId.Remove(filterPatientId.Length - 1, 1))
           Else
               filterExpression = "PatientId IS NULL"
           End If
 
           RadGrid1.DataSource = dtTaxatie.Select(filterExpression)
       Else
           If String.IsNullOrEmpty(filterExpression) Then
               RadGrid1.DataSource = dtTaxatie.DefaultView
           Else
               RadGrid1.DataSource = dtTaxatie.Select(filterExpression)
           End If
       End If
 
       If Not String.IsNullOrEmpty(filterExpression) And Not row Is Nothing Then
           If Not String.IsNullOrEmpty(AppConfig.FilterColumn) Then
               Select Case AppConfig.FilterColumn
                   Case "MITS"
                       columnIdent = "Mits"
                   Case "BSN"
                       columnIdent = "BSN"
                   Case "VIP"
                       columnIdent = "VIP"
               End Select
           Else
               columnIdent = "Mits"
           End If
 
           Dim column As GridColumn = RadGrid1.MasterTableView.GetColumnSafe(columnIdent)
           If Not column Is Nothing Then
               column.CurrentFilterFunction = GridKnownFunction.EqualTo
               Select Case AppConfig.FilterColumn
                   Case "MITS"
                       column.CurrentFilterValue = row.Mitsnummer.ToString()
                   Case "BSN"
                       column.CurrentFilterValue = row.BSNnummer.ToString()
                   Case "VIP"
                       column.CurrentFilterValue = row.VIPnummer.ToString()
               End Select
           End If
       End If
   End Sub

Page (aspx)
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="TaxatieOverzicht.aspx.vb"
    Inherits="EFPRisicoTaxatie.TaxatieOverzicht" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title>Overzicht taxaties</title>
    <meta http-equiv="x-ua-compatible" content="IE=8" />
    <link rel="stylesheet" href="Css/RisicoTaxatie.css" type="text/css" />
    <script language="javascript" type="text/javascript">
        // <!CDATA[
        function RowSelected(sender, args) {
            try {
                var oWnd = GetRadWindow();
                if (oWnd && (args.getDataKeyValue("ID") != '')) {
                    oWnd.close(args.getDataKeyValue("ID"))
                }
            } catch (err) { }
        }
        // ]]>
    </script>
</head>
<body style="background-color: #f0f0f0;">
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Path="~/js/RisicoTaxatie.js"></asp:ScriptReference>
        </Scripts>
    </telerik:RadScriptManager>
    <div style="background-color: #f0f0f0; padding: 0px; margin: 0px;">
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowPaging="True"
            AutoGenerateColumns="False" AllowSorting="True" GridLines="None" Style="z-index: 100;
            left: 0px; position: absolute; top: 0px;" PageSize="15" Width="850px" Height="454px"
            EnableLinqExpressions="False">
            <GroupingSettings CaseSensitive="false" />
            <MasterTableView DataKeyNames="ID" ClientDataKeyNames="ID">
                <Columns>
                    <telerik:GridBoundColumn DataField="Mitsnummer" HeaderText="Nummer" UniqueName="Mits"
                        AutoPostBackOnFilter="true" Visible="false">
                        <ItemStyle Width="75px" />
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="BSNNummer" HeaderText="Nummer" UniqueName="BSN"
                        AutoPostBackOnFilter="true" Visible="false">
                        <ItemStyle Width="75px" />
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="VIPNummer" HeaderText="Nummer" UniqueName="VIP"
                        AutoPostBackOnFilter="true" Visible="false">
                        <ItemStyle Width="75px" />
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Referentie" HeaderText="Naam" UniqueName="Referentie"
                        AutoPostBackOnFilter="true">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="TaxatieIdent" HeaderText="Taxatie" UniqueName="Taxatie"
                        AutoPostBackOnFilter="true">
                        <ItemStyle Width="90px" />
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Datum" HeaderText="Tax.datum" DataFormatString="{0:dd-MM-yyyy}"
                        AllowFiltering="False" UniqueName="TaxatieDatum">
                        <ItemStyle Width="85px" />
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="TypeIdent" HeaderText="Type" AllowFiltering="True"
                        UniqueName="Type">
                        <ItemStyle Width="60px" />
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn HeaderText="Kader" AllowFiltering="False" UniqueName="Kader">
                        <ItemTemplate>
                            <asp:Label ID="lblKader" runat="server"></asp:Label>
                        </ItemTemplate>
                        <ItemStyle Width="120px" />
                    </telerik:GridTemplateColumn>
                    <telerik:GridTemplateColumn HeaderText="situatie" AllowFiltering="False" UniqueName="Situatie">
                        <ItemTemplate>
                            <asp:Label ID="lblsituatie" runat="server"></asp:Label>
                        </ItemTemplate>
                        <ItemStyle Width="120px" />
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
            <PagerStyle Wrap="False" Mode="NumericPages" PagerTextFormat="{4} Pagina {0} van {1}, rij {2} tot {3} van {5}" />
            <ClientSettings EnablePostBackOnRowClick="False">
                <Selecting AllowRowSelect="True" />
                <ClientEvents OnRowDblClick="RowSelected" />
            </ClientSettings>
        </telerik:RadGrid>
    </div>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" EnableAJAX="true">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    </form>
</body>
</html>


 

4 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 01 Apr 2011, 03:00 PM
Hello Stephan,

It appears the filtering in the NeedDataSource event does affect the paging functionality in this case. You can check to see if the correct datasource is passed in each case. This behaviour might happen if you are filtering one source of data but paging on another. It also depends when you initialize the session variable and the data it contains.
Additionally you can refer to this help article showing the recommended approach to set filtering programmatically - you should use the RadGrid.MasterTableView.FilterExpression property in the NeedDataSource event handler.

Best wishes,
Marin
the Telerik team
0
Stephan
Top achievements
Rank 1
answered on 06 Apr 2011, 03:07 PM
Hi Marin,

after reading over your answer a view times, I was wondering how I could set different sources for the grid and the paging in the grid. Is this possible?

Anyway, I checked if on each roundtrip the same datasource was used, which was. So that was not the problem. Still the paging was causing problems when I used it .It still showed to many pages (still bases on the initials information is seems)

However, I was able to solve the problem. Instead of using a datatable, which I did first, I now use a dataview.

This view is filtered in the RowFilter. I have tested it a view times and it seems to work fine.

Dim dtTaxatie As DataView = (New RisicoTaxatieManager()).GetTaxatieOverzicht.DefaultView
      Dim filterExpression As String = String.Empty
      Dim columnIdent As String = String.Empty
      Dim row As RisicoTaxatie.libPatientRow = Nothing
 
      If AppConfig.FilterPatienten Then
          Dim dtPatienten As DataView = (New RisicoTaxatieManager()).GetMedewerkerPatienten(MedewerkerId)
          dtPatienten.RowFilter = "Gekoppeld=1"
          Dim filterPatientId As String = String.Empty
          For Each PatientRow As DataRowView In dtPatienten
              filterPatientId += PatientRow("Id").ToString() + ","
          Next
 
          If Not String.IsNullOrEmpty(filterPatientId) Then
              filterExpression = String.Format("PatientId IN ({0})", filterPatientId.Remove(filterPatientId.Length - 1, 1))
          End If
      End If
 
0
Marin
Telerik team
answered on 07 Apr 2011, 07:31 PM
Hi Stephan,

The paging functionality of the grid is generated based on its datasource, and the number of records in it. You can change the datasource of the grid but paging is based on the same data that the grid is bound to otherwise conflicts will arise. For more information you can check the article about basic paging and custom paging.

All the best,
Marin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Bill
Top achievements
Rank 1
answered on 13 Dec 2012, 12:49 AM
In my case on the pageload I was running a DoFilter method and after setting the filter I was rebinding the grid.
I changed it to rebind the datasource instead and it worked.
DSGMCCMembers.DataBind()
not
RadGrid1.DataBind()
Sub DoFilter()
 
      Dim strFilterClause As String = ""
 
      If chkShowActive.Checked Then strFilterClause = " and (dbo.fnGetUserProfilePropertyValue(0, UserID, N'Status') ='A'"
      If chkshowInActive.Checked Then strFilterClause &= IIf(chkShowActive.Checked, " or ", " and (") & "dbo.fnGetUserProfilePropertyValue(0, UserID, N'Status') ='I'"
      strFilterClause &= ")"
 
      DSGMCCMembers.SelectCommand = "SELECT UserID, DisplayName AS Member, FirstName + ' ' + LastName AS Contact, Email, CreatedOnDate, LastModifiedOnDate, IDCode," _
              & "dbo.fnGetUserProfilePropertyValue(0, UserID, N'Status') AS Status" _
              & " FROM Users AS U" _
              & " WHERE (IsDeleted = 0) AND (IsSuperUser = 0)" _
              & strFilterClause _
              & " ORDER BY Member"
      DSGMCCMembers.DataBind()
 
  End Sub
Tags
Grid
Asked by
Stephan
Top achievements
Rank 1
Answers by
Marin
Telerik team
Stephan
Top achievements
Rank 1
Bill
Top achievements
Rank 1
Share this question
or