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

Column Not Triggering Custom Sorting Event

4 Answers 111 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Scott
Top achievements
Rank 2
Scott asked on 18 Nov 2013, 10:28 PM
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;
    }
}

4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 21 Nov 2013, 04:22 PM
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 >>
0
Scott
Top achievements
Rank 2
answered on 22 Nov 2013, 03:15 PM
Thanks for the response.  Before I repro the issue, could it be due to the fact that the columns not sorting are GridViewImageColumns?
0
Accepted
Dimitrina
Telerik team
answered on 22 Nov 2013, 03:22 PM
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 >>
0
Scott
Top achievements
Rank 2
answered on 22 Nov 2013, 03:27 PM
That was it!! Dang image columns!!
Tags
GridView
Asked by
Scott
Top achievements
Rank 2
Answers by
Dimitrina
Telerik team
Scott
Top achievements
Rank 2
Share this question
or