Display group header name based on other column in nested group

Good day,

I follow this KB article https://www.syncfusion.com/kb/7837/how-to-displaying-group-header-name-based-on-other-column
Everything works fine, when I have one group, but I can't figure out what to do if I have nested groups

For example, I have datagrid with three columns

TopGroup | NestedGroupId | NestedGroupName

In XAML I write:

<sf:SfDataGrid>
    <i:Interaction.Behaviors>
        <h:SfGridBehavior/>
    </i:Interaction.Behaviors>
        <sf:GridTextColumn MappingName="TopGroup"/>
        <sf:GridNumericColumn MappingName="NestedGroupId"/>
        <sf:GridTextColumn IsHidden="True" MappingName="NestedGroupName" />
    </sf:SfDataGrid.Columns>
    <sf:SfDataGrid.GroupColumnDescriptions>
        <sf:GroupColumnDescription ColumnName="TopGroup"/>
        <sf:GroupColumnDescription ColumnName="NestedGroupId"/>
    </sf:SfDataGrid.GroupColumnDescriptions>
</sf:SfDataGrid>

And I want to show NestedGroupName instead of NestedGroupId in group inside TopGroup

With code from knowledge base I'm getting a null-reference exception at

var groupRecords = (groupRecord.Details as GroupRecordEntry).Records;

Could you please give a hint, how to handle a scenario in knowledge base with nested groups?

1 Reply

GT Gnanasownthari Thirugnanam Syncfusion Team October 19, 2017 12:31 PM UTC

Hi Konstantin, 

Thank you for contacting Syncfusion support. 

You can display the group header name based on other columns by getting records from GroupEntry when we having nested Groups as like below code example. 

public void GroupRecordEntry(GroupEntry groupEntry,out string groupName, Group groupRecord,out GridColumn groupedColumn) 
{ 
    groupedColumn = GetGroupedColumn(groupRecord); 
    var groupRecords = ((groupEntry as GroupEntry) .Groups[0] as Group).Details; 
 
    if (groupRecords is GroupEntry) 
    { 
        GroupEntry GroupEntry = groupRecords as GroupEntry; 
        GroupRecordEntry(GroupEntry, out groupName, groupRecord,out groupedColumn); 
    } 
 
    else if (groupRecords is GroupRecordEntry) 
    { 
        //You can get the RecordEntry from Group 
        var GroupRecord = (groupRecords as GroupRecordEntry); 
        GroupName(GroupRecord, out groupName, groupRecord,out groupedColumn); 
    } 
    else  
        groupName = string.Empty;               
} 

We have modified the KB sample as per your requirement, you can download the same from below mentioned location. 

Sample location: 

Please let us know if you need further assistance on this. 

Regards, 
Gnanasownthari T. 


Loader.
Up arrow icon