How to retrieve value of grouped attribute in grid

1 Answer 32 Views
Grid
Ethan
Top achievements
Rank 1
Ethan asked on 16 Jan 2023, 07:29 PM

Hello,

I am trying to set up a GroupFooterTemplate and to calculate a value to put in the footer I need to know the value of the grouped attribute. In this case I am grouping on a column named "Category" and I call a function that needs to know the value of the category column in the group above the footer. If that's not clear here is a screenshot to help illustrate the value I'm trying to find when generating the group footer.

So I'm hoping to be able to pull that category value, "Biological" or "Kiln", when generating the group footer which I do by using the code here.


<GridColumn Field="@lengthColumnName" FieldType="@typeof(decimal)" Title="@myName" Width="180px">
                      <GroupFooterTemplate Context="unitFooterContext">
                              Total: %@calculateSubtotal(lengthColumnName, "Biological").ToString()
                      </GroupFooterTemplate>
</GridColumn>
Currently it is just hard coded to use Biological but I would like it to be able to use the category column value for each group to generate the correct value in each footer under each group. So ideally there is something I can access from the grid that will correspond to the value of the grouped column at each point where the footer is generated (so some variable that would change between biological, kilns, etc as the grid is created).

1 Answer, 1 is accepted

Sort by
0
Hristian Stefanov
Telerik team
answered on 19 Jan 2023, 01:05 PM

Hi Ethan,

Thank you for sending screenshots that help me see the scenario better.

I confirm that you can get the "Category" value in the GridFooterTemplate through the context. Here is how to modify the provided code to make it achieve the desired result:

<GridColumn Field="@lengthColumnName" FieldType="@typeof(decimal)" Title="@myName" Width="180px">
                      <GroupFooterTemplate Context="unitFooterContext">
                              Total: %@calculateSubtotal(lengthColumnName, unitFooterContext.Value).ToString()
                      </GroupFooterTemplate>
</GridColumn>

If we can assist further, I would be glad.

Regards,
Hristian Stefanov
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/.

Ethan
Top achievements
Rank 1
commented on 19 Jan 2023, 08:42 PM

Thank you for your response!

I'm getting a compiler error when trying to use unitFooterContext.Value as a string argument. The error states cannot convert method group to string and I can't seem to figure out how to resolve this issue. Am I missing something about how to access unitFooterContext.Value?

Hristian Stefanov
Telerik team
commented on 23 Jan 2023, 08:49 PM

Hi Ethan,

I retested the configuration in this REPL sample. It seems that the "unitFooterContext.Value" works as expected. Please run and test it by grouping the "Team" column to see if the result you get is the same.

As a next step, use the above sample as a comparison.

I would be glad to keep me updated on how things are going.

Tags
Grid
Asked by
Ethan
Top achievements
Rank 1
Answers by
Hristian Stefanov
Telerik team
Share this question
or