Grid.Blazor
Grid.Blazor copied to clipboard
Setup column grouping programmatically
Example
Here's a grid where I've grouped by Date
and Time
:
The code I used in my Razor Pages page model to turn on grouping:
var server = new GridServer<FoodRecord>(FoodRecord, Request.Query, false, "abcGrid", columns);
grid = server.Grid;
server.Groupable(true);
Question
I'd like to always group by Date
and Time
, without the user having to drag the columns into the grouping field manually.
Is there a way to group by certain columns programmatically?
Same question here, i want to group by default some columns. Is there a way to do this?
Bonus: i'd like to be able to group but without the possibility to change the default grouping for the user.
@dharmatech Did you find how to achieve this?
Thanks.
Has anyone found any information on grouping programatically? I've tried studying the code examples but I can't find anything that would explain how to group programatically. We don't want to use the drag and drop box, but rather want columns set to group during initialization/rendering. The only documentation seems to be calling the GroupAble() method on the Grid class, nothing about how individual columns are grouped.
Checkout OnAfterRenderAsync in ../GridBlazorStandalone/Pages/Groupable.razor
protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { var payloads = new List<ColumnOrderValue>(); payloads.Add(new ColumnOrderValue("Customer.CompanyName", GridSortDirection.Ascending, 1)); payloads.Add(new ColumnOrderValue("ShipVia", GridSortDirection.Ascending, 2)); await _grid.GridComponent.InitGrouping(payloads); } }