Version

External Grouping

Topic Overview

Purpose

This topic explains how to use external grouping with the XamDataGrid™control .

Required background

The following topics are prerequisites to understanding this topic:

Topic Purpose

This topic uses code examples to demonstrate how to add a xamDataGrid control to your page.

This topic introduces the DataPresenter control’s grouping function.

The DataPresenter controls offer a grouping function, which allows end users to group records based on fields that contain the same value.

In this topic

This topic contains the following sections:

Introduction

Introduction to the External Grouping

External Grouping functionality will work similarly to how it works by default (i.e. internally) for xamDataGrid from the UI perspective. Users will be able to drag and drop fields to and from the group-by area to group by the fields.

Note
Note

Limitations are that GroupByMode and GroupByEvaluator settings of the Data Presenter are not supported since ICollectionView is the one performing the grouping operations

Furthermore, grouping by unbound fields is not supported either.

In order to use External Grouping you should set the GroupByEvaluationMode on FieldLayoutSettings to UseCollectionView . The GroupByEvaluationMode enumeration has the following options:

Sort condition type Description

Default

Default is resolved to Auto.

Auto

Grouping mode where grouping occurs internally.

UseCollectionView

Use ICollectionView’s grouping function.

xamDataGrid External grouping – Code Example

Description

This code example demonstrates how to use xamDataGrid’s external grouping feature. This example uses ListViewCollection as the xamDataGrid’s data source, because it implements the ICollectionView interface. This collection is bound to the xamDataGrid and requires that the GroupByEvaluationMode be set to UseCollectionView in order to use it for external grouping.

Prerequisites

Start a new WPF Application project type named ExternalOperations , which includes the following:

  • A reference to the following NuGet package:

    • Infragistics.WPF.DataGrids

  • Classes

    • Item, which inherits INotifyPropertyChanged. Item, this inherits INotifyPropertyChanged. To see the complete code for this class, please refer to the Item class code example topic.

    • Utils class, which creates a ListCollectionView of random items. This is the data source, to which xamDataGrid will be bound. Please refer to the Creating ListCollectionView code example topic for this class’ complete code.

  • Starting window

    • Window named ExternalGrouping.xaml, set as a starting window for the application.

  • Namespace definitions (located in the XAML part of the window, where your will place the mark-up for the xamDataGrid):

    xmlns:igDP=http://infragistics.com/DataPresenter
    xmlns:local="clr-namespace:ExternalOperations"

    (this will be the case for projects named ExternalOperations. If you have chosen a different name, you should change this definition to reflect the new name).

Preview

The following picture illustrates the final rendering of the complied application using external grouping. From the UI perspective, there is no difference whether grouping operations occur externally or internally.

xamDataGrid External Grouping 1.png

Code

In XAML:

<Window x:Class="ExternalOperations.ExternalGrouping"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:igDP="http://infragistics.com/DataPresenter"
        xmlns:local="clr-namespace:ExternalOperations"
        Title="ExternalGrouping" Height="768" Width="1024">
    <DockPanel LastChildFill="True">
        <StackPanel Orientation="Vertical" VerticalAlignment="Stretch" DockPanel.Dock="Top">
            <Button FontWeight="Bold" x:Name="btn100kExternal" Content="Bind to 100k items" Click="btn100kExternal_Click" Width="120" Margin="5"/>
            <Label x:Name="lblExternalTimes" />
        </StackPanel>
        <igDP:XamDataGrid x:Name="xdg100kExternal" VerticalAlignment="Stretch" Grouping="xdg100kExternal_Grouping"
                                      DataSourceResetBehavior="DiscardExistingRecords">
            <igDP:XamDataGrid.FieldLayoutSettings>
                <!-- Here GroupByEvaluationMode is set to UseCollectionView, in order to use the external grouping feature. -->
                <igDP:FieldLayoutSettings GroupByEvaluationMode="UseCollectionView" FilterUIType="FilterRecord"/>
            </igDP:XamDataGrid.FieldLayoutSettings>
            <igDP:XamDataGrid.FieldSettings>
                <igDP:FieldSettings AllowRecordFiltering="True" AllowSummaries="True" SummaryUIType="MultiSelect"
                                                SummaryDisplayArea="BottomFixed" />
            </igDP:XamDataGrid.FieldSettings>
        </igDP:XamDataGrid>
    </DockPanel>
</Window>

In Visual Basic:

Namespace ExternalOperations
      ''' <summary>
      ''' Interaction logic for ExternalGrouping.xaml
      ''' </summary>
      Public Partial Class ExternalGrouping
            Inherits Window
            Public Sub New()
                  InitializeComponent()
            End Sub
            Private Sub btn100kExternal_Click(sender As Object, e As RoutedEventArgs)
                  xdg100kExternal.DataSource = Utils.CreateDataSource(100000)
            End Sub
            Private Sub xdg100kExternal_Grouping(sender As Object, e As GroupingEventArgs)
                  lblExternalTimes.Content = "Grouping..."
                  Dim start As DateTime = DateTime.Now
                  Dispatcher.BeginInvoke(DispatcherPriority.Background, New Action(Function()
                  lblExternalTimes.Content = "Time to group = "(DateTime.Now - start).TotalSeconds
End Function))
            End Sub
      End Class
End Namespace

In C#:

namespace ExternalOperations
{
    /// <summary>
    /// Interaction logic for ExternalGrouping.xaml
    /// </summary>
    public partial class ExternalGrouping : Window
    {
        public ExternalGrouping()
        {
            InitializeComponent();
        }
        private void btn100kExternal_Click(object sender, RoutedEventArgs e)
        {
            xdg100kExternal.DataSource = Utils.CreateDataSource(100000);
        }
        private void xdg100kExternal_Grouping(object sender, GroupingEventArgs e)
        {
            lblExternalTimes.Content = "Grouping...";
            DateTime start = DateTime.Now;
            Dispatcher.BeginInvoke(DispatcherPriority.Background,
                new Action(
                    () =>
                    {
                        lblExternalTimes.Content = "Time to group = " + (DateTime.Now - start).TotalSeconds;
                    }
                    ));
        }
    }
}

Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic explains the external process of filtering the records in xamDataGrid control.

This topic explains the external process of sorting the records in xamDataGrid control.

This topic explains the external summary calculations feature of xamDataGrid .

This is the starting point, where topics written specifically to help you group using the xamDataGrid control are shown.

Samples

The following samples provide additional information related to this topic.

Sample Purpose

Improved performance in Grouping

This sample demonstrates performance ability of the xamDataGrid to group large sets of data.