Column Not Triggering Custom Sorting Event

5 posts, 1 answers
  1. Scott
    Scott avatar
    16 posts
    Member since:
    Oct 2013

    Posted 18 Nov 2013 Link to this post

    I have a RadGridView that is bound to an observable collection of one of my classes.  I have 2 columns bound to a bool DataMember and a converter that displays one image if true and another if false.  For whatever reason, the default sorting doesn't work, so I tried to implement the custom sorting event handler.  Upon clicking the column header, the sorting event doesn't get fired.  I have IsSortable and IsCustomSortingEnabled properties set to True.

    Here is an example of the XAML:
    <telerik:GridViewImageColumn
        Header="PWL"
        DataMemberBinding="{Binding IsOnPotentialWatchList, Converter={StaticResource BoolToCheckOrCrossImageConverter}}"
        IsCustomSortingEnabled="True"
        IsSortable="True"
        HeaderCellStyle="{StaticResource rgvHeaderCellStyle}"
        FooterCellStyle="{StaticResource rgvFooterCellStyleCenter}"
        CellStyle="{StaticResource rgvCellStyle}"
        HeaderTextAlignment="Left"
        TextAlignment="Left"
        Width="Auto" />

    Here is my sorting event:
    protected void OnCreditPolicyGridViewSorting(object sender, Telerik.Windows.Controls.GridViewSortingEventArgs e)
    {
        var cpData = e.DataControl.ItemsSource as IEnumerable<CreditPolicyData>;
        if (cpData == null)
        {
            e.Cancel = true;
            return;
        }
     
        var column = e.Column as Telerik.Windows.Controls.GridViewDataColumn;
        var columnIsPWL = column.GetDataMemberName() == "IsOnPotentialWatchList";
        var columnIsWL = column.GetDataMemberName() == "IsOnWatchList";
        if (columnIsPWL || columnIsWL)
        {
            if (e.OldSortingState == Telerik.Windows.Controls.SortingState.None)
            {
                e.NewSortingState = Telerik.Windows.Controls.SortingState.Ascending;
                         
                if (columnIsPWL)
                    cpData = cpData.OrderBy(cp => cp.IsOnPotentialWatchList);
     
                else if (columnIsWL)
                    cpData = cpData.OrderBy(cp => cp.IsOnWatchList);
            }
            else if (e.OldSortingState == Telerik.Windows.Controls.SortingState.Ascending)
            {
                e.NewSortingState = Telerik.Windows.Controls.SortingState.Descending;
     
                if (columnIsPWL)
                    cpData = cpData.OrderByDescending(cp => cp.IsOnPotentialWatchList);
     
                else if (columnIsWL)
                    cpData = cpData.OrderByDescending(cp => cp.IsOnWatchList);
            }
            else
            {
                e.NewSortingState = Telerik.Windows.Controls.SortingState.None;
                cpData = cpData.OrderBy(cp => cp.SalesmanNumber).ThenBy(cp => cp.CapisNumber);
            }
     
            e.DataControl.ItemsSource = cpData.ToObservableCollection();
                     
            e.Cancel = true;
        }
    }
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 21 Nov 2013 Link to this post

    Hello,

    Generally the Converter is used for UI purpose only, it should not affect the sorting. If you have a DataMemberBinding set to a boolean property, then your values should be sorted based on that boolean value.

    Would it be possible for you to isolate the issue in a demo project and send it to us?

    Regards,
    Didie
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
  4. Scott
    Scott avatar
    16 posts
    Member since:
    Oct 2013

    Posted 22 Nov 2013 Link to this post

    Thanks for the response.  Before I repro the issue, could it be due to the fact that the columns not sorting are GridViewImageColumns?
  5. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 22 Nov 2013 Link to this post

    Hello,

    Thank you for this note. Actually the GridViewImageColumn does not behave as the GridViewDataColumn as it comes to sorting.
    You will need to additionally set  SortMemberPath.
    <telerik:GridViewImageColumn DataMemberBinding="{Binding IsOnPotentialWatchList}" SortMemberPath="IsOnPotentialWatchList"/>

    That way the column will be sorted based on the values of the property you have set.

    Let me know how this works for you?

    Regards,
    Didie
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. Scott
    Scott avatar
    16 posts
    Member since:
    Oct 2013

    Posted 22 Nov 2013 Link to this post

    That was it!! Dang image columns!!
Back to Top
DevCraft banner