We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to use NumberFormatInfo in the SummaryColumn of the GridTableSummaryRow?

Platform: WinRT |
Control: SfDataGrid |
.NET Framework: 4.5

In the SfDataGrid, you can use NumberFormatInfo in the SummaryColumn of the GridTableSummaryRow by deriving a new class from GridTableSummaryCellRenderer and override its OnUpdateEditBinding virtual method. 

 

Note:

By default, summary result is displayed based on the Format specified in SummaryColumn.

 

C#:

public class GridTableSummaryCellRendererExt : GridTableSummaryCellRenderer
    {
        public override void OnUpdateEditBinding(DataColumnBase column, Syncfusion.UI.Xaml.Grid.GridTableSummaryCell element, object dataContext)
        {
            //Check whether the datacontext is SummaryRecordEntry
            var record = dataContext as SummaryRecordEntry;
            if (!(dataContext is SummaryRecordEntry))
                return;
 
            //Process each SummaryColumn and get the display text of corresponding summary
            foreach (ISummaryColumn summaryColumn in record.SummaryRow.SummaryColumns)
            {
                if (!summaryColumn.MappingName.Contains(column.GridColumn.MappingName))
                    continue;
 
                string summarytext = string.Empty;
                if (record.SummaryRow.ShowSummaryInRow)
                    summarytext = SummaryCreator.GetSummaryDisplayTextForRow(record, this.DataGrid.View);
                else
                    summarytext = SummaryCreator.GetSummaryDisplayText(record, column.GridColumn.MappingName, this.DataGrid.View);
 
                if (!string.IsNullOrEmpty(summarytext))
                {
                    //Create new number format and apply it to summary columns 
                    NumberFormatInfo format = new NumberFormatInfo();
                    format.NumberDecimalDigits = 3;
                    format.NumberDecimalSeparator = "*";
                    format.NumberGroupSeparator = ",";
                    //Number format is applied to summary columns
                    element.Content = Convert.ToDouble(double.Parse(summarytext, NumberStyles.Currency)).ToString("N", format);
                }
            }
        }
    }

Refer to the following code example to remove the default GridTableSummaryCellRenderer and add the customized GridTableSummaryCellRendererExt to the renderer’s collection in the SfDataGrid.

C#

public MainWindow()
{
    InitializeComponent();
    //Customized GridTableSummaryCellRendererExt is added to the CellRenderers collection
    grid.CellRenderers.Remove("TableSummary");
    grid.CellRenderers.Add("TableSummary", new GridTableSummaryCellRendererExt()); 
}

 

The above formatting is applied to summary values as follows.

NumberFormatInfo is applied to summary values

Figure 1:NumberFormatInfo is applied to summary values

 

Sample Links:

WPF

 

WinRT

 

WP

 

UWP

 

 

 

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile