Calculated Field Format Not applied when pre-defined in razor

Hello

I have a calculated field pre-defined in my razor like this:

                        <PivotViewCalculatedFieldSettings>
                            <PivotViewCalculatedFieldSetting Name="Percent" Formula="@MyPercentCalc" FormatString="P0" ></PivotViewCalculatedFieldSetting>
                        </PivotViewCalculatedFieldSettings>

The FormatString does not seem to get applied to the calculated filed, so it ends up like this:



1 Reply 1 reply marked as answer

SS Saranya Sivan Syncfusion Team December 14, 2020 06:03 PM UTC

Hi Ditchford, 
  
Based on your requirement we have prepared a sample to apply calculated field settings on code behind .Please check the below sample and code snippet for your reference. 
  
  
Code Example: 
  
  
        <SfPivotView TValue="ProductDetails" Height="340" EnableValueSorting=true ShowFieldList=true AllowCalculatedField=true> 
            <PivotViewDataSourceSettings DataSource="@Data" ExpandAll=false EnableSorting=true> 
                <PivotViewColumns> 
                    <PivotViewColumn Name="Year"></PivotViewColumn> 
                    <PivotViewColumn Name="Quarter"></PivotViewColumn> 
                </PivotViewColumns> 
                <PivotViewRows> 
                    <PivotViewRow Name="Country"></PivotViewRow> 
                    <PivotViewRow Name="Products"></PivotViewRow> 
                </PivotViewRows> 
                <PivotViewValues> 
                    <PivotViewValue Name="Sold" Caption="Units Sold"></PivotViewValue> 
                    <PivotViewValue Name="Amount" Caption="Sold Amount"></PivotViewValue> 
                    <PivotViewValue Name="Percent" Type="SummaryTypes.PercentageOfColumnTotal"></PivotViewValue> 
                </PivotViewValues> 
                <PivotViewCalculatedFieldSettings> 
                    <PivotViewCalculatedFieldSetting Name="Percent" Formula="@MyPercentCalc"> 
                    </PivotViewCalculatedFieldSetting> 
                </PivotViewCalculatedFieldSettings> 
                <PivotViewFormatSettings> 
                    <PivotViewFormatSetting Name="Amount" Format="C0" UseGrouping=true></PivotViewFormatSetting> 
                    <PivotViewFormatSetting Name="Percent" Format="P0" UseGrouping=true></PivotViewFormatSetting> 
                </PivotViewFormatSettings> 
            </PivotViewDataSourceSettings> 
            <PivotViewGridSettings ColumnWidth="120"></PivotViewGridSettings> 
        </SfPivotView>   
  
We hope the above sample meets your requirements. 
  
Regards, 
Saranya Sivan. 


Marked as answer
Loader.
Up arrow icon