wpf-120198-controls-and-libraries-data-grid-bind-to-data-bind-to-any-data-source-with-virtual-sources-use-virtual-sources-step-4-display-summaries.md
You can display summary information about the groups of rows or individual data columns. Complete the following steps:
Explore the full source code in the following examples and demos:
Infinite Scrolling SourceView Example Run DemoPaged SourceView Example Run Demo
The Issues Service allows you to obtain:
public class IssuesSummaries {
public int Count { get; private set; }
public DateTime? LastCreated { get; private set; }
}
Create a task that uses the IssuesService.GetSummariesAsync method to get summaries from the data source.
Use the Summaries property to get GridControl summary items.
Create a GetTotalSummaries command.
Get the list of data source summaries that correspond to GridControl summary items and assign the list to the Result property.
Bind the GetTotalSummaries command to the InfiniteAsyncSource.GetTotalSummariesCommand.
[Command]
public void GetTotalSummaries(GetSummariesAsyncArgs args) {
args.Result = GetTotalSummariesAsync(args);
}
static async Task<object[]> GetTotalSummariesAsync(GetSummariesAsyncArgs args) {
var summaryValues = await IssuesService.GetSummariesAsync((IssueFilter)args.Filter);
return args.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();
}
<dxg:GridControl.ItemsSource>
<dx:InfiniteAsyncSource ElementType="{x:Type local:IssueData}"
FetchRowsCommand="{Binding FetchIssuesCommand}"
GetUniqueValuesCommand="{Binding GetUniqueValuesCommand}"
GetTotalSummariesCommand="{Binding GetTotalSummariesCommand}"/>
</dxg:GridControl.ItemsSource>
Enable the DataViewBase.ShowFixedTotalSummary property to display the Fixed Summary Panel:
<dxg:GridControl.View>
<dxg:TableView ShowFixedTotalSummary="True"/>
</dxg:GridControl.View>
Specify the GridControl.TotalSummary property to display total summaries in the GridControl:
<dxg:GridControl.TotalSummary>
<dxg:GridSummaryItem SummaryType="Count" Alignment="Right"/>
<dxg:GridSummaryItem SummaryType="Max" FieldName="Created"
DisplayFormat="{}Last created: {0}"
Alignment="Right"/>
</dxg:GridControl.TotalSummary>
The Issues Service can calculate the Median and StdDev values:
public class IssuesSummaries {
// ...
public double VotesMedian { get; private set; }
public double VotesStdDev { get; private set; }
}
Process summaries in the virtual source:
Display summaries in the GridControl: