Skip to main content

Step 4: Display Summaries

In this step, you display total summaries in the GridControl bound to a virtual source.

Overview

The Issues Service can get:

  • A total count of rows.
  • The last created object’s datetime.
public class IssuesSummaries {   
    public int Count { get; private set; }
    public DateTime? LastCreated { get; private set; }
}

To Display Summaries

  1. Process summaries in the virtual source:

    • Handle the DevExpress.Data.InfiniteAsyncSource.GetTotalSummaries event.
    • Get summaries from the data source using the Issues Service’s GetSummariesAsync method.
    • Get the GridControl‘s summary items using the DevExpress.Data.GetSummariesEventArgsBase.Summaries property.
    • Return summaries that correspond to the GridControl‘s summary items by specifying the DevExpress.Data.GetSummariesAsyncEventArgs.Result property.
    source.GetTotalSummaries += (o, e) => {
        e.Result = GetTotalSummariesAsync(e);
    };
    static async Task<object[]> GetTotalSummariesAsync(GetSummariesAsyncEventArgs e) {
        IssueFilter filter = MakeIssueFilter(e.Filter);
        var summaryValues = await IssuesService.GetSummariesAsync(filter);
        return e.Summaries.Select(x => {
            if(x.SummaryType == SummaryType.Count)
                return (object)summaryValues.Count;
            if(x.SummaryType == SummaryType.Max && x.PropertyName == "Created")
                return summaryValues.LastCreated;
            throw new InvalidOperationException();
         }).ToArray();
    }
    
  2. Set the DataControlBase.ShowFixedTotalSummary property to true to show the Fixed Summary Panel:

        <Grid:GridControl Name="grid" AutoGenerateColumns="False" AllowSorting="False" AllowColumnFiltering="False"
                          ShowFixedTotalSummary="True">
    
  3. Display total summaries in the GridControl by specifying the GridControl.TotalSummary property:

        <Grid:GridControl.TotalSummary>
             <Grid:GridSummaryItem SummaryType="Count" Alignment="Right" />
             <Grid:GridSummaryItem SummaryType="Max" FieldName="Created" DisplayFormat="{}Last created: {0}" Alignment="Right" />
        </Grid:GridControl.TotalSummary>