Customize Group and Sort

10 posts, 0 answers
  1. Heather
    Heather avatar
    54 posts
    Member since:
    Sep 2010

    Posted 02 Aug 2012 Link to this post

    WPF 4.0 v2012.2.607.35
    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. 
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 03 Aug 2012 Link to this post

    Hello,

     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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Heather
    Heather avatar
    54 posts
    Member since:
    Sep 2010

    Posted 03 Aug 2012 Link to this post

    That does not seem to work consistently with grouping.  If I apply the SortMemberPath without grouping it works perfectly.  If I sort the column by clicking on it then drag the column to the group header it seems to loose the sort.  If I then click on the column header it sorts correctly but if I click on the field in the group by panel it sorts alphanumerically.  And I can't get the sort to default correctly at all if I try to define it in XAML.
    <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>
  5. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 06 Aug 2012 Link to this post

    Hi Heather,

    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.

  6. Heather
    Heather avatar
    54 posts
    Member since:
    Sep 2010

    Posted 08 Aug 2012 Link to this post

    Even if I adjust it in the Grouping event it still ignores the SortMemberPath when the column is being grouped by.  If the column is not being grouped by the SortMemberPath works correctly, if the column is being grouped by then the sort goes back to being alphanumeric based on the value in the InvoiceNumber field.

    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.
  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 13 Aug 2012 Link to this post

    Hello,

    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.

    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 15 Aug 2012 Link to this post

    Hello,

    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.

  9. gisela
    gisela avatar
    15 posts
    Member since:
    Feb 2006

    Posted 10 Apr 2013 Link to this post

    Hi all,

    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
  10. Chaitanya
    Chaitanya avatar
    1 posts
    Member since:
    Dec 2015

    Posted 21 Jan in reply to Dimitrina Link to this post

    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.

  11. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 25 Jan Link to this post

    Hello Chaitanya,

    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? Pasting 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
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready