Good Afternoon,
A few days ago I created this thread on setting the grouping for a grid on initialization and received an excellent solution from Marin Bratanov.
https://www.telerik.com/forums/can-i-set-grid-grouping-and-collapse-on-initialization
Now I am trying to generate multiple grids in a loop for each election race in my list. I was successfully able to do this by creating a local variable and grabbing only the specific race entries with a linq query. All of this works fantastically.
@foreach (VotingMainModel item in ElectionState) { if (item.OfficeName != OfficeName) { <br /> <br /> <h6>@item.OfficeName</h6> IEnumerable<VotingMainModel> electionFilter = ElectionState.Where(x => x.OfficeName.Equals(item.OfficeName)); <TelerikGrid Data="@electionFilter" Groupable="true" @ref="@GridRef" FilterMode="@GridFilterMode.FilterMenu"> <GridAggregates> <GridAggregate Field="@(nameof(VotingMainModel.Votes))" Aggregate="@GridAggregateType.Sum" /> </GridAggregates> <GridColumns> <GridColumn Field="@(nameof(VotingMainModel.OfficeName))" Title="Office" Groupable="true" /> <GridColumn Field="@(nameof(VotingMainModel.Candidate))" Title="Candidate" Groupable="true" /> <GridColumn Field="@(nameof(VotingMainModel.Affiliation))" Title="Affiliation" /> <GridColumn Field="@(nameof(VotingMainModel.Precinct))" Title="Precinct" /> <GridColumn Field="@(nameof(VotingMainModel.Votes))" Title="Votes"> <GroupFooterTemplate> Total Votes: <strong>@context.Sum</strong> </GroupFooterTemplate> </GridColumn> </GridColumns> </TelerikGrid> OfficeName = item.OfficeName; } }
However, I would like to also set the grouping automatically for each table generated. When I get to the OnAfterRenderAsync method I get an error that says "The render handle is not yet assigned" Can I have multiple tables reference the same grid reference if they are the exact same grids with just different data in the tables?
Can I make and assign local gridref variables to each grid..I did try this, but it simply did not group them. I also tried making a list TelerikGrid and tried to add a new TelerikGrid and set the state in the loop this also really didnt do anything.
protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { { await GridRef.SetState(GetDesiredInitialState()); } this.StateHasChanged(); } }