GridPercentColumn Scaling

Hi,

How can I scale the data for the GridPercentColumn?

EX/

Data in DB            I want this to show

0.0453                            4.53

0.1463                          14.63


I would have thought there would be a ScalingFactor = 100.  Similar to the way Excel shows 0.0345 as 3.45% if the cell is a percent format.


Thank you


1 Reply

VS Vijayarasan Sivanandham Syncfusion Team September 2, 2021 07:28 AM UTC

Hi Robert Twickler,

Thank you for contacting Syncfusion Support.

Your requirement can be achieved by override the OnInitializeDisplayElement method by using GridCellPercentageRendererExt in SfDatGrid. Please refer the below code snippet, 
XAML Code Snippet: 
<syncfusion:GridPercentColumn  MappingName="UnitPrice" PercentDecimalDigits="4"                                                  
                                               HeaderText="Unit Price">                    
 </syncfusion:GridPercentColumn> 

C# Code snippet: 
sfDataGrid.CellRenderers.Remove("Percent"); 
sfDataGrid.CellRenderers.Add("Percent", new GridCellPercentageRendererExt());

public class GridCellPercentageRendererExt : GridCellPercentageRenderer 
{        
        public override void OnInitializeDisplayElement(DataColumnBase dataColumn, TextBlock uiElement, object dataContext) 
        { 
            base.OnInitializeDisplayElement(dataColumn, uiElement, dataContext); 
            var binding = new Binding 
            { 
                Path = new PropertyPath("UnitPrice"), 
                StringFormat = "{0:P}", 
            }; 
 
            uiElement.SetBinding(TextBlock.TextProperty, binding); 
        } 
}   

For more information related to GridPercentColumn, please refer the user guide documentation,

UG Link: https://help.syncfusion.com/wpf/datagrid/column-types#gridpercentcolumn 

Please let us know, if you require further assistance on this.

Regards,
Vijayarasan S 


Loader.
Up arrow icon