Generate aggregates via c# code

Dear Syncfusion,

I am working with a grid, binded to an ExpandoObject, where the column names and even the number of columns are arbitrary. I managed to create the columns via c# code, using the following markup/code:

<SfGrid @ref="myGrid" DataSource="@Orders" Columns="@myCols">
@code {List<GridColumn> myCols = new List<GridColumn>();}

Now I have to define aggragates too, via code. I presume it should be something like this:

<SfGrid @ref="myGrid" DataSource="@Orders" Columns="@myCols" Aggregates="@myAggregates">
@code {List<GridAggregate> myAggregates = new List<GridAggregate>();}

But here I am lost. Do you have an example where I can see how to build the Aggregates, please?


5 Replies 1 reply marked as answer

RS Renjith Singh Rajendran Syncfusion Team December 15, 2021 03:15 AM UTC

Hi Peter, 
  
Greetings from Syncfusion support. 
  
We would like to inform you that, it is not possible to render aggregate rows using Aggregates property of SfGrid. As informed in the below API reference documentation, Aggregates property will only get the aggregate rows, the Grid aggregate rows could be rendered only using the component way as provided in our below reference links.  
 
So, we suggest you to use the GridAggregates component to configure and render the aggregate rows in Grid. 
Reference :  
  
Please get back to us if you need further assistance. 
  
Regards, 
Renjith R 



PE Peter December 15, 2021 11:04 AM UTC

Dear Renjith,

thanks for the quick answer. What I realised is that all my "problems" are related to one cardinal fact: I have to show in a grid a dataset, what changes. The number of columns, the name of the fields are depending on user interaction. The result itself arrives to me in an ExpandoObject, and I have to render it into the grid, with summaries, group summariest, etc.

It seems for me that the easiest way would be to generate the <SfGrid></SfGrid> part on the fly via c# code, however I have no idea how to inject the new markup into the page. It seems the MarkupString is not the good solution, and as a last resort I begun to study the RenderFragment.

Can you please guide me how can that be solved? Is that solveable at all as I imagined, or maybe Blazor is just not working that way? Clearly my knowledge is very limited in this.



RS Renjith Singh Rajendran Syncfusion Team December 16, 2021 09:20 AM UTC

Hi Peter, 
 
Based on your update, we have prepared a sample to render SfGrid via C# code. Please download and refer the sample from the link below, 
 
Please get back to us if you need further assistance. 
 
Regards, 
Renjith R 


Marked as answer

PE Peter December 16, 2021 04:42 PM UTC

Dear Renjith,

thank you for the example, and for your efforts to help to solve my problem. 

With best regards:

Peter



VN Vignesh Natarajan Syncfusion Team December 17, 2021 08:21 AM UTC

Hi Peter,  

Thanks for the update.  

We are glad to hear that you have resolved your query using our solution.  

Please get back to us if you have further queries. 

Regards, 
Vignesh Natarajan   


Loader.
Up arrow icon