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:
Here is my sorting event:
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
;
}
}