Hi,
I've seen the aggregates in the documentation however I'm wondering something else. I couldn't find an example. Is it possible to display the sum and average of the selected cells at the footer of the grid like Excel?
Thanks!
Hi Adem,
Greetings from Syncfusion Support.
Query: "Is it possible to display the sum and average of the selected cells on the grid at the footer like Excel?"
We understand your query and it's possible to display sum and average value based on selected column by using GetSelectedRecordsAsync() function to retrieve the selected row data and calculating aggregate value based on it. Before that we want know, if you need to aggregate value based on initially selected rows or calculate aggregate value on selected rows on run time itself. So that it will be very helpful for us to provide the solution as early as possible.
Please get back to us, if you have any further queries
Regards,
Sarveswaran PK
Hi Sarveswaran,
That's great to hear! I want to calculate aggregate value on selected rows on run time itself.
Just to clarify, I put an example below. Imagine you have a table just like in the picture and some cells of the Proficiency column have been selected. Then you see the sum and average of the selected cells at the footer.
Hi Adem,
Greetings from Syncfusion Support.
Query: "Is it possible to display the sum and average of the selected cells on the grid at the footer like Excel?"
We have checked your query and achieved your requirement with help of custom aggregate function by using GetSelectedRecordAsync() method. You may calculate the aggregate value with your own aggregate functions, use the custom aggregate option. Please find attached sample and code snippet for your reference.
|
Counter.razor
<GridAggregateColumns> <GridAggregateColumn Field=@nameof(Product.TotalSales) Type="AggregateType.Custom"> <FooterTemplate> @{ var test = @GetSelectedRecords(); <div> <p>Custom:@test.Result</p> </div> } </FooterTemplate> </GridAggregateColumn> </GridAggregateColumns>
&
public List<Product> Products { get; set; } List<Product> SelectedRecords { get; set; }
public async Task<string> GetSelectedRecords() { //calculate custom aggregate operations
double total = 0; SelectedRecords = await Grid.GetSelectedRecordsAsync(); if (SelectedRecords?.Count > 0) {
foreach (var Record in SelectedRecords) { total = total + Record.TotalSales ; } } return total.ToString(); } |
Please refer our UG Documentation : https://blazor.syncfusion.com/documentation/datagrid/aggregates#custom-aggregate
Kindly get back to us if you have further queries.
Regards
Sarveswaran PK
Hi Sarveswaran,
Thanks for your response. This is definitely useful. I didn't know the GetSelectedRecordsAsync function. However, what I'm trying to achieve is a bit more complex than this. I'm trying to create a generic solution for the calculation of the sum and average regardless of the column.
Imagine that you have many numeric columns in your data grid as in the picture below.
Then I select the area 1 from the column Open and the sum and average are calculated. After that, I deselect the area 1 and select the area 2 from the column High. The sum and average of the selected cells are displayed at the same location. In short, I want the property in the picture below to be determined based on the selected cells.
I've been playing with the multiple cell selection feature of datagrid since last week. As far as I've experienced, such feature is not supported by default. But I want to hear it from you.
Thanks!
Hi Adam,
Thanks for contacting Syncfusion support again.
We have analyzed your query and we understand that you want to display aggregate values based on multiple columns of selected data under the Grid component. But we have provided support to display the aggregate values specific to column. So it is not possible to achieve your requirement of displaying the aggregate value based on selected records.
If you have further queries, please get back to us
Regards,
Sarveswaran PK