I have a grid of charges that are on invoices. I want to show the charges by most recent invoice but sorting on the invoice number sorts incorrectly because it is a text field. What I need to do is group by and show the InvoiceNumber but sort by the InvoiceId descending and not have the InvoiceId shown anywhere.
9 Answers, 1 is accepted
Indeed the text fields will be sorted as string. You can set SortMemberPath="InvoiceId" for the "InvoiceNumber" column. Then the sorting will be done on the "InvoiceId" column.
All the best,Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
<
ctrls:BPGridView
Grid.Row
=
"0"
AutoGenerateColumns
=
"False"
ItemsSource
=
"{Binding Items}"
SelectedItem
=
"{Binding SelectedItem,Mode=TwoWay}"
AutoExpandGroups
=
"True"
>
<
telerik:RadGridView.GroupDescriptors
>
<
telerik:GroupDescriptor
Member
=
"InvoiceNumber"
DisplayContent
=
"Invoice"
SortDirection
=
"Descending"
/>
</
telerik:RadGridView.GroupDescriptors
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewBoundColumnBase
Header
=
"Description"
DataMemberBinding
=
"{Binding ChargeDescription}"
ShowDistinctFilters
=
"False"
>
<
telerik:GridViewBoundColumnBase.CellTemplate
>
<
DataTemplate
>
<
TextBlock
>
<
Hyperlink
Command
=
"{Binding DataContext.SelectCommand, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView}}}"
CommandParameter
=
"{Binding}"
Style
=
"{StaticResource BPHyperlinkStyle}"
>
<
TextBlock
Text
=
"{Binding ChargeDescription}"
/>
</
Hyperlink
>
</
TextBlock
>
</
DataTemplate
>
</
telerik:GridViewBoundColumnBase.CellTemplate
>
<
telerik:GridViewBoundColumnBase.AggregateFunctions
>
<
telerik:CountFunction
Caption
=
"Count: "
/>
</
telerik:GridViewBoundColumnBase.AggregateFunctions
>
</
telerik:GridViewBoundColumnBase
>
<
telerik:GridViewDataColumn
Header
=
"Amount"
DataMemberBinding
=
"{Binding ChargeTotal, StringFormat=\{0:c\}}"
FooterCellStyle
=
"{StaticResource GridNoLinesFooterStyle}"
ShowDistinctFilters
=
"False"
/>
<
telerik:GridViewDataColumn
Header
=
"Service"
DataMemberBinding
=
"{Binding ServiceOfferingName}"
FooterCellStyle
=
"{StaticResource GridNoLinesFooterStyle}"
ShowDistinctFilters
=
"True"
/>
<
telerik:GridViewDataColumn
Header
=
"Effective Date"
DataMemberBinding
=
"{Binding Path=EffectiveDate, StringFormat=\{0:d\}}"
FooterCellStyle
=
"{StaticResource GridNoLinesFooterStyle}"
/>
<
telerik:GridViewDataColumn
Header
=
"Type"
DataMemberBinding
=
"{Binding Path=ChargeTypeName}"
FooterCellStyle
=
"{StaticResource GridNoLinesFooterStyle}"
/>
<
telerik:GridViewDataColumn
x:Name
=
"invcol"
Header
=
"Invoice"
SortMemberPath
=
"InvoiceIdSort"
DataMemberBinding
=
"{Binding Path=InvoiceNumber,TargetNullValue=None}"
FooterCellStyle
=
"{StaticResource GridNoLinesFooterStyle}"
/>
<
telerik:GridViewDataColumn
Header
=
"Date Created"
DataMemberBinding
=
"{Binding Path=DateCreated, StringFormat=\{0:d\}}"
FooterCellStyle
=
"{StaticResource GridNoLinesFooterStyle}"
/>
<
telerik:GridViewDataColumn
Header
=
"Invoiced"
DataMemberBinding
=
"{Binding Path=InvoicedFlag}"
FooterCellStyle
=
"{StaticResource GridNoLinesFooterStyle}"
/>
</
telerik:RadGridView.Columns
>
</
ctrls:BPGridView
>
You may adjust the resulting sort state by handling the grouping event of RadGridView. Inside the event handler you may set the desired sorting state.
I case you need a sample on this , please paste the implementation of your Invoice objects and I will gather a small runnable project for you.
All the best,
Pavel Pavlov
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
Example Data:
InvoiceIdSort=10 InvoiceNumber="0412"
InvoiceIdSort=9 InvoiceNumber = "0312"
InvoiceIdSort=8 InvoiceNumber="0212"
InvoiceIdSort=7 InvoiceNumber="0411"
InvoiceIdSort=6 InvoiceNumber="0311"
InvoiceIdSort=5 InvoiceNumber="0211"
Using the XAML from earlier posting if you remove the grouping then the data is correctly sorted by the InvoiceIdSort value, If I then group by the InvoiceNumber column, the sort uses the InvoiceNumber field value NOT the InvoiceIdSort field value.
Thank you for that additional information. We will need a little bit more time to check the problem. I will write back to you with more relative information tomorrow.
Thank you for your patience.
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
You can sort the grouped InvoiceNumber column based on the value of the InvoiceIdSort like so:
private
void
clubsGrid_Grouping(
object
sender, GridViewGroupingEventArgs e)
{
if
(e.Action == GroupingEventAction.Place)
{
e.Cancel =
true
;
var descriptor =
new
GroupDescriptor<Club,
string
,
int
>
{
GroupingExpression = i => i.InvoiceNumber,
GroupSortingExpression = i => i.FirstOrDefault().InvoiceIdSort
};
descriptor.DisplayContent = ((Telerik.Windows.Data.GroupDescriptorBase)(e.GroupDescriptor)).DisplayContent;
descriptor.SortDirection = e.GroupDescriptor.SortDirection;
this
.clubsGrid.GroupDescriptors.Add(descriptor);
}
}
In my code snippet the bound object is of type Club.
Kind regards,
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
your code works fine, except the AggregateFunctions (of another colums) are not executed and the GroupFooter is empty. How can i achieve, that this works.
Thanks in advance
Hi Team,
var descriptor = new GroupDescriptor<Club, string, int>
{
GroupingExpression = i => i.InvoiceNumber,
GroupSortingExpression = i => i.FirstOrDefault().InvoiceIdSort
};
When I am using this, data is been grouped properly but when I try to sort by clicking on grouped element from group header. it is giving System.Reflection.TargetInvocationException, can you please help me.
As I am unable to reproduce the exception, could you check if there are any inner exceptions and if so, post them here so that we can have a look? Could you also please provide more information about the application you've set up? some code snippets would definitely be of help.
If you prefer, you can open a new support ticket where you could send us a sample project, demonstrating the exception.
Regards,
Dilyan Traykov
Telerik