How can I insert text in a group footer's cell?
01.
public
MainWindow()
02.
{
03.
InitializeComponent();
04.
05.
var style =
new
Style();
06.
style.Setters.Add(
new
Setter(GroupHeaderRow.ShowGroupHeaderColumnAggregatesProperty,
false
));
07.
style.Setters.Add(
new
Setter(GroupHeaderRow.ShowHeaderAggregatesProperty,
false
));
08.
var radGrid =
new
RadGridView { GroupRenderMode = GroupRenderMode.Flat, GroupRowStyle = style};
09.
Content = radGrid;
10.
11.
// Table schema
12.
var data =
new
DataTable();
13.
var user = data.Columns.Add(
"User"
);
14.
var cat = data.Columns.Add(
"Category"
);
15.
var amt = data.Columns.Add(
"Amount"
,
typeof
(
decimal
));
16.
17.
// Populate values
18.
var catValues =
new
[] {
"Cat A"
,
"Cat B"
,
"Cat C"
};
19.
for
(var i = 0; i < 20; i++)
20.
{ data.Rows.Add(
"User "
+ i, catValues[i % catValues.Length], i * 100d); }
21.
22.
// Prepare RadGridView
23.
radGrid.ItemsSource = data;
24.
radGrid.AutoExpandGroups =
true
;
25.
radGrid.ShowColumnFooters =
true
;
26.
radGrid.AutoGenerateColumns =
false
;
27.
28.
// Build RadGrid columns
29.
var gridColumns =
new
[] {user, cat, amt}
30.
.Select(dataColumn =>
new
GridViewDataColumn
31.
{
32.
UniqueName = dataColumn.ColumnName,
33.
DataMemberBinding =
new
Binding(dataColumn.ColumnName),
34.
})
35.
.ToList();
36.
radGrid.Columns.AddRange(gridColumns);
37.
38.
// Sum Amount
39.
var amtCol = gridColumns.Last();
40.
var amtFormat =
"{0:C}"
;
41.
amtCol.DataFormatString = amtFormat;
42.
amtCol.AggregateFunctions.Add(
new
SumFunction()
43.
{
44.
SourceField = amt.ColumnName,
45.
SourceFieldType = amt.DataType,
46.
ResultFormatString = amtFormat
47.
});
48.
radGrid.ShowGroupFooters =
true
;
49.
50.
// Group by category
51.
var catGroup =
new
GroupDescriptor { Member = cat.ColumnName, };
52.
radGrid.GroupDescriptors.Add(catGroup);
53.
54.
// Show grand total label
55.
radGrid.Columns[0].Footer =
"Grand Total"
;
56.
57.
// todo: How to show group subtotal label?
58.
59.
}