Hi Marin,
thanks for the quick response.
That works well indeed. My error was that I forgot to include the grouped column in the grid definition.
Regards,
Ewald
Hi Ewald,
Have you had a chance to try the OnStateInit event: https://docs.telerik.com/blazor-ui/components/grid/state#set-default-initial-state?
Here's a sample I made for you that seems to work fine: https://blazorrepl.telerik.com/QPlmlvOZ02KK6pio32. If this does not help you move forward, I recommend opening a support ticket where you can share more details and snippet so we can look into the situation.
Regards,
Marin Bratanov
Progress Telerik
None of the methods in the examples seem to work when the data for the grid are fetched asynchronously.
Please provide an example where data is fetched in the OnInitializedAsync() method.
Regards,
Ewald
Hi Tom,
The group indicator does not have, and should not have access to the data. It should show which field/column is used to group by. THere may be many values to group by and they can't all be shown in the indicator. They are shown in the group header, and for that - there is a template: https://docs.telerik.com/blazor-ui/components/grid/templates#group-header
Please open a ticket if you can't get around the available documentation so I can help you according to the case, and so we don't spam everyone else who monitored the grouping from code feature.
Regards,
Marin Bratanov
Progress Telerik
Hi Marin,
We're getting closer. The grouping using the OnStateInit method now works as desired. It would be nice if you added the code to the example shown in the documentation. The documentation only shows how to set the SortDirection.
However, your example of how to set the DisplayContent is insufficient. I don't want a constant string but rather the value, in my case, of the category field on which I am doing the grouping. Or, in your example, the name of the team being grouped on. There is no intelliSense displayed when setting the DisplayContent.
Hi Tom,
The OnStateInit event is what you use to do that, and using it is showcased in the documentation article.
If you want to use the .SetState() method, you must use the OnAfterRender event, because that's when component references are populated by the framework.
The DisplayContent field of the group descriptor can alter what you see in the group indicator, even though it is supposed to be the column name by default so the users can make the connection between the grouping and the column/field. Its intellisense comment provides instructions on setting a string.
I made an example for this (attached below), and if you have further questions I'd ask that you open a support ticket or a forum thread so we can keep the portal clean - it is a place for tracking and discussing new features and bugs, and not for general purpose technical support, and we won't spam everyone who has been following this feature.
@using Telerik.DataSource;
<TelerikGrid Data="@MyData" Height="400px" Groupable="true" Navigable="true"
Pageable="true" FilterMode="@GridFilterMode.FilterMenu"
OnStateInit="@((GridStateEventArgs<SampleData> args) => OnStateInitHandler(args))">
<GridColumns>
<GridColumn Field="@(nameof(SampleData.Id))" Width="120px" Groupable="false" />
<GridColumn Field="@(nameof(SampleData.Name))" Title="Employee Name" />
<GridColumn Field="@(nameof(SampleData.Team))" Title="Team" />
<GridColumn Field="@nameof(SampleData.IsOnLeave)" Title="On Vacation" />
<GridColumn Field="@(nameof(SampleData.HireDate))" Title="Hire Date" />
</GridColumns>
</TelerikGrid>
@code {
async Task OnStateInitHandler(GridStateEventArgs<SampleData> args)
{
GridState<SampleData> desiredState = new GridState<SampleData>()
{
GroupDescriptors = new List<GroupDescriptor>()
{
new GroupDescriptor()
{
Member = "Team",
DisplayContent = "TEAM GROUP INDICATOR", // this is how to set the string for the group indicator
MemberType = typeof(string)
},
new GroupDescriptor()
{
Member = "IsOnLeave",
MemberType = typeof(bool),
SortDirection = ListSortDirection.Descending // not required, but a feature not yet available through the UI
}
}
};
// this is how to pass the state object you generate to the grid in the OnStateInit event
args.GridState = desiredState;
}
public IEnumerable<SampleData> MyData = Enumerable.Range(1, 30).Select(x => new SampleData
{
Id = x,
Name = "name " + x,
Team = "team " + x % 5,
IsOnLeave = x % 2 == 0,
HireDate = DateTime.Now.AddDays(-x).Date
});
public class SampleData
{
public int Id { get; set; }
public string Name { get; set; }
public string Team { get; set; }
public bool IsOnLeave { get; set; }
public DateTime HireDate { get; set; }
}
}
Regards,
Marin Bratanov
Progress Telerik
Neither of your references describe how to show the grid with the grouping already applied. Clicking on a button after the grid appears works fine, but that's not what I want to do. Calling the SetGridGroup method (modified for my code) in OnInitializedAsync causes an exception: "The render handle is not yet assigned". So the question is: Where should the SetGridGroup method be called?
Also, how can you change the default display of the group title? Currently, in my case, the title shows "category: Medical". category is the name of the field being grouped on. I just want the title to Medical in this case. There is a DisplayContent property in the GroupDescriptor which seems like that is where I would make the change I desire but I haven't been able to figure out what the syntax is. Please provide some examples of the use of this field.
Hello Tom,
There are several examples you can use as base:
The entire article about the grid state offers more examples and explanations on what the state contains and does, so you might find it useful in its entirety.
Regards,
Marin Bratanov
Progress Telerik
Perhaps it should allow defining default collapsed/expanded state for the given group field as well, see here.
Regards,
Marin Bratanov
Progress Telerik