Version

External Summary Calculations (xamDataGrid)

Topic Overview

Purpose

This topic explains and demonstrates the xamDataGrid™ control’s external summary calculation feature.

Required background

The following topics are prerequisites to understanding this topic:

Topic Purpose

This topic’s intention is to get you up and running as quickly as possible by describing the basic steps required for adding the xamDataGrid control.

You can give your end users the ability to select the row summaries for a field in xamDataPresenter.

Main Features Summary

SummaryEvaluationMode

The FieldLayoutSettings SummaryEvaluationMode property has the following enumerations:

Settings Description

Default

The SummaryEvaluationMode’s default setting is Auto.

Auto

The grouping mode, which employs internal summary calculations.

Manual

The data presenter will not calculate summary values. You will have to perform the calculations and provide the result via the data presenter’s QuerySummaryResult event.

UseLINQ

Use LINQ for calculating summaries.

Note
Note

Filtering only affects what is shown in the xamDataGrid, but the data source is not changed. Summaries, on the other hand, are based on the whole data source and not on the filtered in subset of the data source. If you need to have summaries which are calculated based on a filtered in subset of the data source you need to use a CollectionView based data source and set the FilterEvaluationMode property to UseCollectionView.

In XAML:

<igDP:XamDataGrid x:Name="xamDataGrid">
    <igDP:XamDataGrid.FieldLayoutSettings>
        <igDP:FieldLayoutSettings
            FilterEvaluationMode="UseCollectionView"
            SummaryEvaluationMode="UseLinq" />
    </igDP:XamDataGrid.FieldLayoutSettings>
</igDP:XamDataGrid>

In C#:

ObservableCollection<Item> Items;
var View = CollectionViewSource.GetDefaultView(Items);
this.xamDataGrid.DataSource = View;

In Visual Basic:

Dim Items As ObservableCollection(Of Item)
Dim View = CollectionViewSource.GetDefaultView(Items)
Me.xamDataGrid.DataSource = View

QuerySummaryResult

This event is raised whenever the data presenter is about to calculate a summary result.

QuerySummaryResultEventArgs

QuerySummaryResultEventArgs class exposes properties and methods, which are useful for calculating summary results using your custom logic.

Summary Evaluation Mode

Set the SummaryEvaluationMode on FieldLayoutSettings to UseLINQ to use external summary calculations.

Note
Note:

The underlying data items and sources must support LINQ.

Query Summary Result

QuerySummaryResult, event on DataPresenterBase, is raised regardless of what the SummaryEvaluationMode is set to.

You can calculate summary value using custom logic and provide the summary result value to the data presenter.

Query Summary Result EventArgs

QuerySummaryResultEventArgs class exposes the following properties and methods, which is useful for calculating summary values using custom logic.

Property Description

Gets the SummaryResult object, once calculated and provides the context for the record collection.

Method Description

SetSummaryValue(Object value)

Provides a custom calculated summary result, which in turn causes the data presenter to bypass its own calculation logic and use the value provided for the result instead.

Calling this method with a non-null argument bypasses the data presenter’s calculation logic.

xamDataGrid External Summaries Calculations – Code Example

Description

This example demonstrates the basics of performing the xamDataGrid control’s external summaries calculations, which uses ICollectionView as its data source and LINQ to calculate the summaries.

Prerequisites

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

  • Infragistics NuGet Package Reference:

    • Infragistics.WPF.DataGrids

  • Classes

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

    • 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 for this class’ complete code.

  • Starting window

    • Window named ExternalSummaries.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"

Preview

This is the preview of the final application displaying summary calculations.

xamDataGrid External Summary Calculations 1.png

Code

In XAML:

<Window x:Class="ExternalOperations.ExternalSummaries"
        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="ExternalSummaries" Height="768" Width="1024">
    <DockPanel LastChildFill="True">
        <StackPanel Orientation="Vertical" VerticalAlignment="Stretch" DockPanel.Dock="Top">
            <Button FontWeight="Bold" x:Name="btnManyRecordsExternal" Content="Bind to 5 000 000 items" Click="btnManyRecordsExternal_Click"  Width="150" Margin="5"/>
            <Label x:Name="lblExternalTimes" />
        </StackPanel>
        <igDP:XamDataGrid x:Name="xdg5mlExternal" VerticalAlignment="Stretch" QuerySummaryResult="xdg5mlExternal_QuerySummaryResult"
                          DataSourceResetBehavior="DiscardExistingRecords">
            <igDP:XamDataGrid.FieldLayoutSettings>
                <!-- Here SummaryEvaluationMode is set to UseLinq in order to use external summaries feature.  -->
                <igDP:FieldLayoutSettings SummaryEvaluationMode="UseLinq"/>
            </igDP:XamDataGrid.FieldLayoutSettings>
            <igDP:XamDataGrid.FieldSettings>
                <igDP:FieldSettings AllowSummaries="True" SummaryUIType="MultiSelect" SummaryDisplayArea="Top" />
            </igDP:XamDataGrid.FieldSettings>
        </igDP:XamDataGrid>
    </DockPanel>
</Window>

In Visual Basic:

Namespace ExternalOperations
      Public Partial Class ExternalSummaries
            Inherits Window
            Public Sub New()
                  InitializeComponent()
            End Sub
            Private Sub btnManyRecordsExternal_Click(sender As Object, e As RoutedEventArgs)
                  xdg5mlExternal.DataSource = Utils.CreateDataSource(5000000)
            End Sub
            Private Sub xdg5mlExternal_QuerySummaryResult(sender As Object, e As Infragistics.Windows.DataPresenter.Events.QuerySummaryResultEventArgs)
                  lblExternalTimes.Content = "Calculating summaries..."
                  Dim start As DateTime = DateTime.Now
                  Dispatcher.BeginInvoke(DispatcherPriority.Background, New Action(Function()
                  lblExternalTimes.Content = "Time to calculate = " + (DateTime.Now - start).TotalSeconds
End Function))
            End Sub
      End Class
End Namespace

In C#:

namespace ExternalOperations
{
    public partial class ExternalSummaries : Window
    {
        public ExternalSummaries()
        {
            InitializeComponent();
        }
        private void btnManyRecordsExternal_Click(object sender, RoutedEventArgs e)
        {
            xdg5mlExternal.DataSource = Utils.CreateDataSource(5000000);
        }
        private void xdg5mlExternal_QuerySummaryResult(object sender, Infragistics.Windows.DataPresenter.Events.QuerySummaryResultEventArgs e)
        {
            lblExternalTimes.Content = "Calculating summaries...";
            DateTime start = DateTime.Now;
            Dispatcher.BeginInvoke(DispatcherPriority.Background,
                new Action(
                    () =>
                    {
                        lblExternalTimes.Content = "Time to calculate = " + (DateTime.Now - start).TotalSeconds;
                    }
                    ));
        }
    }
}

Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic explains how to use External Filtering with xamDataGrid .

This topic explains how to use external grouping with XamDataGrid .

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

This topic gives an overview of XamDataGrid feature for External Sorting, Filtering, Grouping and Summaries.

Samples

The following samples provide additional information related to this topic.

Sample Purpose

External Summary Calculations

This sample demonstrates the ability to perform summary calculations in xamDataGrid externally.