Declined
Last Updated: 13 Oct 2020 07:36 by ADMIN
Phil
Created on: 07 Oct 2020 15:28
Category: UI for Blazor
Type: Feature Request
0
Configure Blazor Grid Column Footer Template Aggregates Programatically

In our application, we have the need for aggregate functions in the grid which are determined at runtime, not design time. We were able to get this working for Group footers using a combination of the GroupFooterTemplate element and determining the applicable aggregates in OnStateInit and OnStateChanged. When our team saw that the FooterTemplate element was added, we were excited to bring "Grand Summary" functionality to this grid on top of the existing group summaries. As far as we have been able to determine, however, there doesn't appear to be a way, currently, to add AggregateDescriptors dynamically for the entire grid like we can for groups. We can do the aggregate operations manually against the data source, but this doesn't take into account and filtering which is applied to the grid. We have been unable to find any way of adding AggregateDescriptors for the overall Grid like we can for groups within the GridState's GroupDescriptor property.

Attached are two files: StateInitializationC#Code and gridRazor.txt, which contain relevant snippets of what we are currently doing.

 

3 comments
ADMIN
Marin Bratanov
Posted on: 13 Oct 2020 07:36

Hi Phil,

Can you confirm that the instructions and setup for the grid data from this section are implemented: https://docs.telerik.com/blazor-ui/components/grid/manual-operations#grouping-with-onread? If so, please send me a small runnable example that shows the problem. My best guess is that some settings are not initialized properly or are missing hence the null reference exception.

 

Regards,
Marin Bratanov
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

Phil
Posted on: 12 Oct 2020 13:52

Thank you for those links Marin! They did help me quite a bit, though I am now running into a new issue.

Once I add an OnRead handler for the grid, I start to get the following error:

System.ArgumentNullException: Value cannot be null. (Parameter 'source')
   at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
   at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
   at Telerik.Blazor.Components.TelerikGrid`1.GetGroupRenderIndexes(IEnumerable`1 groups, Dictionary`2 groupRenderIndexes, Int32& absoluteGroupIndex, Int32& renderedGroupsCount, Int32& renderedRowsCount, Int32 renderIndexStartOffset)
   at Telerik.Blazor.Components.TelerikGrid`1.GetRowRenderIndexes(IEnumerable`1 groups)
   at Telerik.Blazor.Components.TelerikGrid`1.SetProcessedData(IEnumerable data)
   at Telerik.Blazor.Components.Common.DataBoundComponent`1.OnParametersSetAsync()
   at Telerik.Blazor.Components.TelerikGrid`1.<>n__0()
   at Telerik.Blazor.Components.TelerikGrid`1.OnParametersSetAsync()
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost: Error: Unhandled exception in circuit 'qJumsWtazbCiFKEbYSYrIXGEUgjAjghQSa9nPUC6Eas'.

 

This occurs sometime after the OnRead event and occurs even if nothing is actually done in the OnRead event.

I get this error in both of the following scenarios:

  • All logic is the same as in the samples provided, but with the addition of an empty OnRead handler.
  • Removed StateChanged and StateInit handlers from sample and migrated logic into OnRead handler

This only appears to occur when I have a grid with Grouping (which is applied at runtime either by the State handlers or the OnRead handler in the appropriate scenarios above.)

Can you please advise? Is there something that I might have not configured that can resolve this error, or is this a bug/unsupported scenario?

ADMIN
Marin Bratanov
Posted on: 08 Oct 2020 11:11

Hi Phil,

To start with the summary - such logic is up to the application and the paragraphs below will give you a pointer on how to implement it.

While you could use conditional markup to add or remove aggregates, I don't think it will be more efficient than defining them up front - syncing all the code between defined aggregates, actual data source operations and template code is error-prone, in my opinion.

As for custom and/or dynamic calculations and aggregates - you can check the example with OnRead in the Notes section of the docs: https://docs.telerik.com/blazor-ui/components/grid/templates/column-footer#notes - it shows one way you can customize the DataSourceRequest, and also how you can plug your own code in the templates - you can add your own aggregates as needed by the app without defining them in the grid or without having the grid calculate them for you. 

Aggregation is not something the end user can define and as such it is part of the data logic in the app, not the grid state. The example above shows one way to aggregate data, and also the e.Request.Aggregates collection lets you alter the aggregates in the grid through the OnRead event which is where customization of the data operations is done anyway (see more here and the sections about caching the DataSourceRequest and about extracting information from it may be helpful to you).

Regards,
Marin Bratanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.