I am using this sample to implement server-side grouping:
https://github.com/telerik/blazor-ui/tree/master/grid/datasourcerequest-on-server/WasmApp
Now I need Aggregate sum for the price in the GroupFooterTemplate. When I add aggregates, exceptions are thrown if a group footer uses the aggregate value, if not - the grid simply does not look grouped.
---
ADMIN EDIT
The issue stems from the inability of the System.Text.Json to deserialize interfaces - there are a couple of interfaces in the datasource request and data source result related to aggregates. Preliminary review indicates that perhaps some or all of them might be changed to, for example, Dictionary<string, object> from the current IDictionary<string, object>, or perhaps the framework might "learn" to deserialize interfaces.
----
Here is a working Converters for AggregateResult and AggregateFunction.
https://blazorrepl.telerik.com/mpYQaRbr37AmEXvM26
Note: Make sure to add the converters both to your client and server app:
services.AddControllers()
.AddJsonOptions(o =>
{
o.JsonSerializerOptions.Converters.Add(new AggregateResultJsonConverter());
o.JsonSerializerOptions.Converters.Add(new AggregateFunctionConverter());
o.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
o.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
})
CamelCase is importent so the AggregateFunctionConverter works.
On Client, you have to set the JsonOptions with each request:
private readonly JsonSerializerOptions jsonOptions = new()
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
};
My custom HttpClient to handle this:
public HttpClientHandeld(HttpClient client, IToastService toastService)
{
this.client = client;
this.toastService = toastService;
this.jsonOptions.Converters.Add(new AggregateResultJsonConverter());
}
Get:
var response = await this.client.GetFromJsonAsync<T>(requestUri, this.jsonOptions);
Post:
var response = await this.client.PostAsJsonAsync(requestUri, value, this.jsonOptions);
Hi Philip and everyone,
I realize this feature may be important for you, but I admit we are focused on tasks with higher custom demand. Sorry about that.
If this is a showstopper for you, perhaps you can experiment with you own custom (manual) serialization? Another possible option is to calculate aggregates separately and render them in group footer and footer templates.
Regards,
Dimo
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.