The default format for the Caption summary row in the sfDataGrid when grouping is "{ColumnName} : {Key} - {ItemsCount}
Item(s)";
Is easy to change the display format of the ColumnName for a single group like if my group column name in the model is ColumnCrypticName I want to show "Cryptic Meaning" I just hardcode it in the GroupCaptionTextFormat.
Of course I can always change the name of the columns in the model but I can't because I don't control the database.
Is there a way to change the display text for a column based on the group level when using multiple groups?
I couldn't find any examples on the matter.
Thanks
Hi George,
We have created a simple sample that meets your requirements. In this sample, we have replaced the default DataGridCaptionSummaryCellRenderer with the CustomCaptionSummaryCellRenderer. With the new renderer, you can customize the view to meet your specific needs by overriding the OnInitializeDisplayView() function. We have attached a sample and a code snippet for your reference.
Code snippet:
|
public class CustomCaptionSummaryCellRenderer : DataGridCaptionSummaryCellRenderer { protected override void OnInitializeDisplayView(DataColumnBase dataColumn, SfDataGridLabel? view) { base.OnInitializeDisplayView(dataColumn, view);
if(view is not null && dataColumn is not null && dataColumn.RowData is not null) { var level = (dataColumn.RowData as Group)!.Level; view.Text = view.Text + " Level: " + level; } } } |
Regards,
Nirmalkumar
Thank you. That approach works great.
This is what I actually wanted now using your solution:
protected override void OnInitializeDisplayView(DataColumnBase dataColumn, SfDataGridLabel? view)
{
base.OnInitializeDisplayView(dataColumn, view);
if(view is not null && dataColumn is not null && dataColumn.RowData is not null)
{
var level = (dataColumn.RowData as Group)!.Level;
switch (level)
{
case 1:
view.Text = view.Text.Replace("Gender", "Sex");
break;
case 2:
view.Text = view.Text.Replace("MaritalStatus", "Civil Status");
break;
}
//view.Text = view.Text + " Level: " + level;
}
Seems that is not an uncommon requirement to require different display strings for column names.
It will be nice if we could use a little more declarative style like:
<syncfusion:SfDataGrid.GroupColumnDescriptions>
<syncfusion:GroupColumnDescription ColumnName="Gender" DisplayName="Sex" />
<syncfusion:GroupColumnDescription ColumnName="MaritalStatus" DisplayName="Civil Status" />
</syncfusion:SfDataGrid.GroupColumnDescriptions>
or
protected override void OnAttachedTo(SfDataGrid dataGrid)
{
dataGrid.GroupColumnDescriptions.Add(new GroupColumnDescription()
{
ColumnName = "Gender",
DisplayName="Sex",
KeySelector = (string ColumnName, object o) =>
{
var gender = ((Employee)o).Gender;
return gender;
}
});
dataGrid.GroupColumnDescriptions.Add(new GroupColumnDescription()
{
ColumnName = "MaritalStatus",
DisplayName = "Civil Status",
KeySelector = (string ColumnName, object o) =>
{
var status = ((Employee)o).MaritalStatus;
return status;
},
});
base.OnAttachedTo(dataGrid);
}
Thanks again
Hi George,
As of now, DataGrid does not have support for customizing the display name of grouped column. We have already considered your request as a feature. We will implement this feature in any of our upcoming releases. At the planning stage for every release cycle, we review all open features and identify features for implementation based on specific parameters including product vision, technological feasibility, and customer interest. We appreciate your patience and understanding until then. You can follow up with the below feedback for further details,
Feedback link: 56838
Regards,
Nirmalkumar