public class CustomCaptionSummaryCellRenderer : GridCaptionSummaryCellRenderer
{
public override void OnInitializeEditElement(DataColumnBase dataColumn, GridCaptionSummaryCell uiElement, object dataContext)
{
if (dataContext is Group)
{
var groupRecord = dataContext as Group;
var mappingName = dataColumn.GridColumn.MappingName;
var groupedColumn = this.GetGroupedColumn(groupRecord);
if (mappingName == groupedColumn.MappingName)
uiElement.Content = groupRecord.Key;
else
uiElement.Content = SummaryCreator.GetSummaryDisplayText(groupRecord.SummaryDetails,
dataColumn.GridColumn.MappingName, this.DataGrid.View);
}
}
public override void OnUpdateEditBinding(DataColumnBase dataColumn, GridCaptionSummaryCell element, object dataContext)
{
if (element.DataContext is Group && this.DataGrid.View.GroupDescriptions.Count > 0)
{
var groupRecord = element.DataContext as Group;
//get the column which is grouped.
var groupedColumn = this.GetGroupedColumn(groupRecord);
var mappingName = dataColumn.GridColumn.MappingName;
if (mappingName == groupedColumn.MappingName)
element.Content = groupRecord.Key;
else
element.Content = SummaryCreator.GetSummaryDisplayText(groupRecord.SummaryDetails,
dataColumn.GridColumn.MappingName, this.DataGrid.View);
}
}
// Method to get the Grouped Column.
private GridColumn GetGroupedColumn(Group group)
{
var groupDesc = this.DataGrid.View.GroupDescriptions[group.Level - 1] as PropertyGroupDescription;
foreach (var column in this.DataGrid.Columns)
{
if (column.MappingName == groupDesc.PropertyName)
{
return column;
}
}
return null;
}
} |