VirtualServerModeSource.TotalSummary Event
Fires when a grid control asks the data source to calculate total summaries.
Namespace: DevExpress.Data
Assembly: DevExpress.Data.v24.1.dll
NuGet Package: DevExpress.Data
Declaration
Event Data
The TotalSummary event's data class is VirtualServerModeTotalSummaryEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
CancellationToken | Gets a token that allows you to respond to a task cancellation request invoked by the grid control. |
ConfigurationInfo | Gets information on the grid’s current sorting, filtering and summary configuration. |
NotReadyObject | This member supports the internal infrastructure. |
TotalSummaryTask | Gets or sets the task that returns the requested summary value. |
The event data class exposes the following methods:
Method | Description |
---|---|
NotifyIntermediateSummaryReady(IDictionary<ServerModeSummaryDescriptor, Object>) | |
NotifySummaryReady(IDictionary<ServerModeSummaryDescriptor, Object>) | Allows you to update the bound grid control with intermediate summary values. |
Remarks
To supply the requested total summary values, create a Task that calculates these values and assign it to the VirtualServerModeTotalSummaryEventArgs.TotalSummaryTask event parameter. Use the VirtualServerModeTotalSummaryEventArgs.ConfigurationInfo parameter to identify the requested summaries.
You can provide the bound grid with intermediate summary results during the task execution. To accomplish this, call the VirtualServerModeTotalSummaryEventArgs.NotifyIntermediateSummaryReady method from the Task.
The created Task must return final values for all requested summaries, including those whose intermediate values are supplied with the NotifyIntermediateSummaryReady method.
Tip
A Task typically executes asynchronously. To return summary values synchronously, create the task with the Task.FromResult method (available in .NET Framework 4.5+).
Example
This example demonstrates how to handle the TotalSummary
event to calculate the total summaries.
using using DevExpress.Data;
using using DevExpress.Data.Filtering;
using using System.Collections.Generic;
private void VirtualServerModeSource1_TotalSummary(object sender, VirtualServerModeTotalSummaryEventArgs e) {
e.TotalSummaryTask = new System.Threading.Tasks.Task<IDictionary<ServerModeSummaryDescriptor, object>>(GetSummaries, e.ConfigurationInfo.TotalSummary);
}
IDictionary<ServerModeSummaryDescriptor, object> GetSummaries(object descriptors) {
Dictionary<ServerModeSummaryDescriptor, object> results = new Dictionary<ServerModeSummaryDescriptor, object>();
int i = 0;
foreach (ServerModeSummaryDescriptor descriptor in descriptors as ServerModeSummaryDescriptor[]) {
results.Add(descriptor, GetSummary(descriptor.SummaryPropertyName, descriptor.SummaryType, i++));
}
return results;
}
object GetSummary(string fieldName, Aggregate summaryType, int index) {
if (fieldName == "ID" && summaryType == Aggregate.Sum && index == 0)
return 5;
if (fieldName == "ID" && summaryType == Aggregate.Avg && index == 1)
return 10;
if (fieldName == "ID" && summaryType == Aggregate.Avg && index == 2)
return 15;
return null;
}