Aggregates Custom

I'm using Syncfusion version 18.2.0.59 and I'm trying to show in a datagrid footer a custom aggregates value like sum(column1 * column2) but I don't find any sample for Blazor pages
In detail, this is the piece of code I'm using where I don't know the syntax to use in the CustomAggregate = ?

                <GridAggregates>
                            <GridAggregate>
                                <GridAggregateColumns>
                                        <GridAggregateColumn Type="AggregateType.Custom" CustomAggregate="@CustomAggregatesFN">
                                            <FooterTemplate>
                                                @{
                                                    var aggregate = (context as AggregateTemplateContext);
                                                    <div>
                                                        <p>Sum: @aggregate.Sum.</p>
                                                    </div>
                                                }
                                            </FooterTemplate>
                                        </GridAggregateColumn>
                                </GridAggregateColumns>
                            </GridAggregate>
                </GridAggregates>

and the syntax of CustomAggregatesFN function is also to me unknown
I tried this:

     public int CustomAggregatesFN(MagvenditeDTO args)
    {
        return args.Punteggio * args.Qta;
    }

I receive an error in the sintax of what I highlighted in orange above but probably because it's wrong the syntax of the function definition ?


9 Replies 1 reply marked as answer

JP Jeevakanth Palaniappan Syncfusion Team September 30, 2020 06:37 AM UTC

Hi Walter, 

Greetings from Syncfusion support. 

We have validated your query and you can achieve your requirement by modifying your code as like below. Please find the below code snippet and the sample for your reference. 

<GridAggregates> 
    <GridAggregate> 
        <GridAggregateColumns> 
            <GridAggregateColumn Field=@nameof(Product.UnitsInStock) Type="AggregateType.Custom"> 
                <FooterTemplate> 
                    @{ 
                        var aggregate = (context as AggregateTemplateContext); 
                        <div> 
                            <p>Weighted Aggregate: @GetWeightedAggregate()   </p> 
                        </div> 
                    } 
                </FooterTemplate> 
            </GridAggregateColumn> 
        </GridAggregateColumns> 
    </GridAggregate> 
</GridAggregates> 
 
@code{ 
 
    public string WeightedAggregate = ""; 
 
//Custom Aggregate Function 
    public string GetWeightedAggregate() 
    { 
        return Queryable.Sum(Products.Select(x=>x.UnitsInStock * x.UnitsInStock1).AsQueryable()).ToString("N4"); 
    } 
 
} 


Please get back to us if you need further assistance. 

Regards, 
Jeevakanth SP. 


Marked as answer

WM Walter Martin October 1, 2020 08:13 AM UTC

Thank you Jeevakanth
your sample works fine and helped me a lot to complete my project.
Actually it didn't work in my version 18.2.0.44 in case the grid would be empty at the beginning and filled after clicking on a button because I received the error but I updated to version 12.2.0.54 and everything works.
I can't update to the latest 12.2.0.59 because I'm waiting for a solution to a bug found in that version.
Thanks



JP Jeevakanth Palaniappan Syncfusion Team October 2, 2020 05:41 AM UTC

Hi Walter, 

Thanks for the Update. Please get back to us if you have any other queries. 

Regards, 
Jeevakanth SP. 



SA Sarah replied to Jeevakanth Palaniappan May 2, 2024 12:12 PM UTC

Hello

I used CustomAggregate.

In the DataGrid, I use paging and filter. Suppose the DataGrid has 1000 rows, after the filter, 500 rows are displayed in the DataGrid on several pages. In GetCurrentViewRecordsAsync(), the output of this function is only the rows of the current page. How can I get 500 rows?



PS Prathap Senthil Syncfusion Team May 3, 2024 03:07 PM UTC

Hi Sarh,



Based on your query, we would like to inform you that the GetCurrentViewRecordsAsync method returns only the data present in the current page of the DataGrid. If paging is applied in the DataGrid, it will retrieve the current view records. This behavior is the default of the grid and it's not feasible to retrieve all records using the GetCurrentViewRecordsAsync method. Thank you for your understanding.

Regards,
Prathap S



SA Sarah replied to Prathap Senthil May 4, 2024 11:30 AM UTC

Hi Prathap Senthil,

Thank you for your attention

How can I get all records displayed on all pages?



PS Prathap Senthil Syncfusion Team May 6, 2024 11:50 AM UTC

We would like to inform you that when using paging, initially, you will receive the current view records in the grid's data source. Subsequent sets of records will be loaded when moving to the next page. The grid's paging feature operates based on the skip-and-take values for on-demand loading. Therefore, it's not feasible to fulfill your requirement of retrieving the entire records for all pages. This is the default behavior of the grid. Thank you for your understanding.




SA Sarah May 6, 2024 03:09 PM UTC

It is suggested to put a function to get all the records available on all the pages.

Without this function, we cannot know about the records that are displayed on the user's side.



PS Prathap Senthil Syncfusion Team May 7, 2024 01:21 PM UTC


We understand your requirement for a function to retrieve all records available on all pages in the Syncfusion Blazor DataGrid. However ,As mentioned in our previous communication, the DataGrid's paging feature operates on-demand loading based on skip-and-take values. While we understand the importance of having visibility into all records for certain scenarios, retrieving all records from all pages simultaneously might not be feasible due to performance and resource constraints, especially with large datasets. Thank you for your understanding of this limitation.


Loader.
Up arrow icon