How to get a reference to the underlying TValue within a GridAggregateColumn

How can you get a reference to the underlying object (TValue) within a GridAggregateColumn? The value is the result of calculating two different fields.

          <GridAggregateColumn Field=@nameof(Models.Position.Gains) Type="AggregateType.Custom">
                        <FooterTemplate>
                            @{
                                   // Need a reference to the Models.Position? The result will be displayed in this column
                                  var percentage = context.Gains / context.Cost;
                               
                                <div>
                                    @percentage.ToString("P2")
                                </div>
                            }
                        </FooterTemplate>
                        <GroupFooterTemplate>
                            @{
                                  // Need a reference to the Models.Position?
                                  var percentage = context.Gains / context.Cost;
                               
                                <div>
                                    @percentage.ToString("P2")

                                </div>
                            }
                        </GroupFooterTemplate>
                    </GridAggregateColumn>

1 Reply 1 reply marked as answer

RS Renjith Singh Rajendran Syncfusion Team March 24, 2021 11:05 AM UTC

Hi Matt, 

Greetings from Syncfusion support. 
 
Based on this scenario, we suggest you to do your custom calculation to display aggregate using the value which you are assigning for the DataSource property of Grid. We suggest you to fetch the required field values from the DataSource list and do your custom calculations. 

 
<SfGrid @ref="Grid" DataSource="@Products" AllowGrouping="true" AllowPaging="true"> 
    ... 
    <GridAggregates> 
        <GridAggregate> 
            <GridAggregateColumns> 
                <GridAggregateColumn Field=@nameof(Product.UnitsInStock) Type="AggregateType.Sum"> 
                    ... 
                    <FooterTemplate> 
                        @{ 
                            //Perform your custom calculation using the Grid's DataSource property value(Products 
                            //And display the result in aggregate template 
                        } 
                    </FooterTemplate> 
                </GridAggregateColumn> 
            </GridAggregateColumns> 
        </GridAggregate> 
    </GridAggregates> 
    ... 
</SfGrid> 

 

Please get back to us if you need further assistance. 

Regards, 
Renjith R 


Marked as answer
Loader.
Up arrow icon