paging and clearing filters

5 posts, 1 answers
  1. David Ocasio
    David Ocasio avatar
    147 posts
    Member since:
    Nov 2009

    Posted 02 Jul 2012 Link to this post

    I have what i beleive to be a bug (2012.2.607.1050 version)
    although it could be the way i am doing it

    I needed a button that would clear all the filters that have been set up on a radgridview that was
    fed by a domaindatasource/pager

    I used code that was posted by the admin Ross for clearing the filters
    Private Sub btnClear_Click(sender As Object, e As System.Windows.RoutedEventArgs) Handles btnClear.Click
        radGridView.FilterDescriptors.SuspendNotifications()
        For Each column In radGridView.Columns
            If column.FilteringControl IsNot Nothing Then
            Else
                column.ClearFilters()
            End If
        Next
        radGridView.FilterDescriptors.ResumeNotifications()
    End Sub

    What i found was some unusal behavior where multiple loads were being started on the DDS.

    In an effort to demonstarte this behavior i authored a short demo/test against the northwind database
    I removed the domaindatasource and replaced it with a QueryableDomainServiceCollectionView

    if you filter a number of columns
    Then change the page to 2 or 3 or any page except the first one
    Press the clear button.

    Multiple loads will be started and completed
    See code and Debug Output below

    is there somehting i am doing wrong
    is there a better way
    is it a bug (i think so)

    thanks
    dco

    <UserControl x:Class="agTesty6.MainPage"
            mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
         
        <Grid x:Name="LayoutRoot">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
     
            <telerik:RadGridView x:Name="radGridView"
                                 Grid.Row="0"
                                 ItemsSource="{Binding DataView}"
                                 ShowGroupPanel="False"
                                 AutoGeneratingColumn="OnRadGridViewAutoGeneratingColumn"
                                 IsReadOnly="True"/>
                 
            <telerik:RadDataPager x:Name="radDataPager"  
                                  PageSize="10"
                                  Grid.Row="1"
                                  AutoEllipsisMode="Both"
                                  NumericButtonCount="10"
                                  Source="{Binding DataView}"
                                  DisplayMode="All"
                                  IsTotalItemCountFixed="True"/>
            <Button Content="Clear" Grid.Row="2" Margin="4" Width="75" HorizontalAlignment="Right" x:Name="btnClear"  />
        </Grid>
    </UserControl>
    Imports System
    Imports System.Linq
    Imports System.Windows.Controls
    Imports Telerik.Windows.Controls.DomainServices
    Imports Telerik.Windows.Data
    Partial Public Class MainPage
        Inherits UserControl
     
        Public Sub New()
            InitializeComponent()
     
            Dim domainContext As New agTesty6.Web.NorthWindDomainContext
     
            Dim query = domainContext.GetCustomers_OrderedQuery
            _DataView = New QueryableDomainServiceCollectionView(Of agTesty6.Web.Customer)(domainContext, query)
     
            Me.DataContext = Me
            _DataView.AutoLoad = True
     
        End Sub
     
        Public ReadOnly Property DataView() As QueryableCollectionView
            Get
                Return _DataView
            End Get
        End Property
        Private WithEvents _DataView As QueryableDomainServiceCollectionView(Of agTesty6.Web.Customer)
     
        Private Sub OnRadGridViewAutoGeneratingColumn(sender As System.Object, e As Telerik.Windows.Controls.GridViewAutoGeneratingColumnEventArgs)
        End Sub
     
        Private Sub btnClear_Click(sender As Object, e As System.Windows.RoutedEventArgs) Handles btnClear.Click
            radGridView.FilterDescriptors.SuspendNotifications()
            For Each column In radGridView.Columns
                If column.FilteringControl IsNot Nothing Then
                Else
                    column.ClearFilters()
                End If
            Next
            radGridView.FilterDescriptors.ResumeNotifications()
        End Sub
     
        Private Sub _DataView_LoadedData(sender As Object, e As Telerik.Windows.Controls.DomainServices.LoadedDataEventArgs) Handles _DataView.LoadedData
            System.Diagnostics.Debug.WriteLine("Dataview Loaded Data -- " & e.Entities.Count)
        End Sub
     
        Private Sub _DataView_LoadingData(sender As Object, e As Telerik.Windows.Controls.DomainServices.LoadingDataEventArgs) Handles _DataView.LoadingData
            System.Diagnostics.Debug.WriteLine("======================")
            System.Diagnostics.Debug.WriteLine("Dataview Loading Data")
            System.Diagnostics.Debug.WriteLine(e.Query.Query)
        End Sub
    End Class

    ======================
    Dataview Loading Data
    agTesty6.Web.Customer[].Where(item => item.CompanyName.ToLower().Contains("s".ToLower())).Skip(30).Take(10)
    Dataview Loaded Data -- 10
    ======================
    Dataview Loading Data
    agTesty6.Web.Customer[].Take(10)
    ======================
    Dataview Loading Data
    agTesty6.Web.Customer[].Take(10)
    ======================
    Dataview Loading Data
    agTesty6.Web.Customer[].Skip(30).Take(10)
    Dataview Loaded Data -- 10
    Dataview Loaded Data -- 10
    Dataview Loaded Data -- 10
  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 03 Jul 2012 Link to this post

    Hello,

    Do you have this sample project targeting Northwind? Can you send it to me for debugging?

    Regards,
    Ross
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. David Ocasio
    David Ocasio avatar
    147 posts
    Member since:
    Nov 2009

    Posted 03 Jul 2012 Link to this post

    Ok 
    I opened support ticket 561359
    So i could upload the demo solution for your review.
    I referenced this forum as well as your name in the ticket.

    thanks ross
    dco
  5. Answer
    Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 03 Jul 2012 Link to this post

    Hi,

    Can you please add this code to your source code:
    Private Sub btnClear_Click(sender As Object, e As System.Windows.RoutedEventArgs) Handles btnClear.Click
        Using (_DataView.DeferRefresh())
            radGridView.FilterDescriptors.SuspendNotifications()
            For Each column In radGridView.Columns
                If column.FilteringControl IsNot Nothing Then
                Else
                    column.ClearFilters()
                End If
            Next
            radGridView.FilterDescriptors.ResumeNotifications()
        End Using
    End Sub

    When the QDSCV is on a page different from the first one, it will try to move back to page 0 after a dramatic change occurs, i.e. filtering, that is why it may load a couple of times. If you surround the de-filtering in a DeferRefresh call all should happen in a single batch operation.

    I hope this helps.

    Regards,
    Ross
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. David Ocasio
    David Ocasio avatar
    147 posts
    Member since:
    Nov 2009

    Posted 03 Jul 2012 Link to this post

    Thanks ross

    That does work

    Had to refactor a little since my production code has a radomaindatasource as opposed to the QueryableDomainServiceCollectionView
    I used in the example and the "DeferRefresh" is not exposed.

    But it does work as you said.

    thanks
    dco
Back to Top
DevCraft banner