AggregateType.Custom is not exist in blazor grid.

Hi Great Support,
I have seen in document "AggregateType.Custom" is not exist in Blazor grid;
https://blazor.syncfusion.com/documentation/datagrid/aggregates/

But in code its exist;


I need to aggregate two columns summery  summery result in same place. Are there any other way todo in with out "AggregateType.Custom" ? 

7 Replies 1 reply marked as answer

RN Rahul Narayanasamy Syncfusion Team August 7, 2020 02:25 PM UTC

Hi Blazor, 

Greetings from Syncfusion. 

We have validated your query and you want perform custom aggregation. Currently we have problem with custom aggregation and logged it as a bug and defect report “Custom aggregate is not working in blazor”. Thank you for taking the time to report this issue and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle ) and including the defect fix in our upcoming  Volume 2 SP release which is expected to be rolled out on mid of August, 2020.     
    
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.    
    
    
Until then we appreciate your patience.     
  
Regards,  
Rahul 


Marked as answer

BL Blazor October 22, 2020 02:08 PM UTC

Hi Good news,

I have checked the documetation;
https://blazor.syncfusion.com/documentation/datagrid/aggregates/


I couln't see any example about custom agregate. Can you please give me simple expamle?


RN Rahul Narayanasamy Syncfusion Team October 23, 2020 03:14 PM UTC

Hi Blazor, 
 
Query: Custom aggregate - I couln't see any example about custom agregate. Can you please give me simple expamle? 
 
We have validated your query and we have prepared a sample based on your requirement. Here, we have created a sample with custom aggregate. Find the below code snippets and sample for your reference. 
 
 
<SfGrid @ref="Grid" DataSource="@Products" AllowPaging="true"> 
    <GridAggregates> 
        <GridAggregate> 
            <GridAggregateColumns> 
                <GridAggregateColumn Field=@nameof(Product.UnitsInStock) Type="AggregateType.Custom"> 
                    <FooterTemplate> 
                        @{ 
                            var aggregate = (context as AggregateTemplateContext); 
                            <div> 
                                <p>Weighted Aggregate: @GetWeightedAggregate()   </p>  //here we have calculated two columns value and rendered in custom aggregate 
                            </div> 
                        } 
                    </FooterTemplate> 
                </GridAggregateColumn> 
            </GridAggregateColumns> 
        </GridAggregate> 
    </GridAggregates> 
    <GridColumns> 
        . . . 
    </GridColumns> 
</SfGrid> 
 
@code{ 
    SfGrid<Product> Grid { get; set; } 
    public List<Product> Products { get; set; } 
    private string[] Units = (new string[] { "QuantityPerUnit" }); 
    public string WeightedAggregate = ""; 
    public string GetWeightedAggregate() 
    { 
        // perform grouping and sorting as per the grouped column  
        return Queryable.Sum(Products.Select(x=>x.UnitsInStock + x.UnitsInStock1).AsQueryable()).ToString("N4");   
 
    } 
    . . . 
} 
 
 
Please let us know if you have any concerns. 
 
Regards, 
Rahul 



GI gisela February 18, 2021 09:07 AM UTC

Hi Rahul,

can you give me a sample for a custom aggregate funtion, when the grid or some columns has the property "AllowFiltering = true". How i can get the filtered rows ?

Thank's in advance
gisela


RN Rahul Narayanasamy Syncfusion Team February 19, 2021 01:32 PM UTC

Hi Gisela, 

Greetings from Syncfusion. 

Query: can you give me a sample for a custom aggregate funtion, when the grid or some columns has the property "AllowFiltering = true". How i can get the filtered rows ? 

We have validated your query and we suspect that you want to update the aggregate value while performing filtering operation. Here, we have prepared a sample based on your requirement. We have achieved this requirement using OnActionComplete event and GetFilteredRecords method of the Grid. Find the below code snippets and sample for your reference. 

You can get the filtered records using GetFilteredRecords method of the Grid. 

Reference: 

 
<SfGrid @ref="Grid" DataSource="@Products" AllowPaging="true" AllowFiltering="true"> 
    <GridEvents OnActionComplete="Complete" TValue="Product"></GridEvents> 
    <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> 
    <GridColumns> 
        <GridColumn Field=@nameof(Product.ProductName) HeaderText="Product Name" TextAlign="TextAlign.Right" Width="150"></GridColumn> 
        . . . 
    </GridColumns> 
</SfGrid> 
 
@code{ 
    SfGrid<Product> Grid { get; set; } 
    public List<Product> Products { get; set; } 
    public object Filterd { get; set; } 
    private string[] Units = (new string[] { "QuantityPerUnit" }); 
    public string WeightedAggregate = ""; 
    public string GetWeightedAggregate() 
    { 
        if(Filterd == null)  //check whether has filtered records or not 
        { 
            return Queryable.Sum(Products.Select(x => x.UnitsInStock + x.UnitsInStock1).AsQueryable()).ToString("N4");   //return calculated aggregate value for all records 
        } else 
        { 
            var fildterData = (List<Product>)Filterd; 
            return Queryable.Sum(fildterData.Select(x => x.UnitsInStock + x.UnitsInStock1).AsQueryable()).ToString("N4");  //return calculated aggregate value for filtered records 
        } 
    } 
 
    public async Task Complete(ActionEventArgs<Product> args) 
    { 
        if (args.RequestType == Syncfusion.Blazor.Grids.Action.Filtering) 
        { 
            Filterd = await Grid.GetFilteredRecords();   //get filtered records 
        } 
    } 
    . . . 
} 


Reference

Please let us know if you have any concerns. 

Regards, 
Rahul 



WM Walter Martin March 28, 2021 11:07 PM UTC

Your sample works fine
Is there any option to add also the AggregateType.custom for grouped data ?
I need the Weighted Aggregate   for allowfiltering=true and allowgrouping=true
Is this possible ?
I tried to add the following piece of code to your sample but I received a null reference object

                    <GroupCaptionTemplate>
                        @{
                            var aggregate = (context as AggregateTemplateContext);
                            <div>
                               <p>Weighted Aggregate: @GetWeightedAggregate()</p>
                            </div>
                        }
                    </GroupCaptionTemplate>



RN Rahul Narayanasamy Syncfusion Team March 29, 2021 01:04 PM UTC

Hi Walter, 

Greetings from Syncfusion. 

We have validated your query and you want to call custom aggregate function while enabling filtering and grouping functionalities. We suggest you to achieve your requirement by using below way. 

 
<SfGrid @ref="Grid" DataSource="@Products" AllowPaging="true" AllowGrouping="true" AllowFiltering="true"> 
    <GridEvents OnActionComplete="Complete" TValue="Product"></GridEvents> 
    <GridAggregates> 
        <GridAggregate> 
            <GridAggregateColumns> 
                <GridAggregateColumn Field=@nameof(Product.UnitsInStock) Type="AggregateType.Sum">    
                    <FooterTemplate> 
                        @{ 
                            var aggregate = (context as AggregateTemplateContext); 
                            <div> 
                                <p>Weighted Aggregate: @GetWeightedAggregate()   </p  //call your custom function here.. 
                            </div> 
                        } 
                    </FooterTemplate> 
                    <GroupCaptionTemplate> 
                        @{ 
                            var aggregate = (context as AggregateTemplateContext); 
                            var a = 4; 
                            <div> 
                                @*<p>Group Aggregate: @CustomdAggregateCalc()   </p>*@     //call your custom function here.. 
                                <p>Group Aggregate: @aggregate.Sum   </p>         //or define default value 
                            </div> 
                        } 
                    </GroupCaptionTemplate> 
                </GridAggregateColumn> 
            </GridAggregateColumns> 
        </GridAggregate> 
    </GridAggregates> 
    <GridColumns> 
        . . . 
    </GridColumns> 
</SfGrid> 


Please let us know if you have any concerns. 

Regards, 
Rahul 


Loader.
Up arrow icon