gustavnavar / Grid.Blazor

Grid component with CRUD for Blazor (client-side and server-side) and ASP.NET Core MVC
GNU Lesser General Public License v2.1
705 stars 135 forks source link

Setup column grouping programmatically #288

Open dharmatech opened 3 years ago

dharmatech commented 3 years ago

Example

Here's a grid where I've grouped by Date and Time:

image

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?

cportet-simpleter commented 3 years ago

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.

rlebowitz commented 3 years ago

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.

SolidDesignCore commented 2 years ago

Checkout OnAfterRenderAsync in ../GridBlazorStandalone/Pages/Groupable.razor

protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { var payloads = new List(); payloads.Add(new ColumnOrderValue("Customer.CompanyName", GridSortDirection.Ascending, 1)); payloads.Add(new ColumnOrderValue("ShipVia", GridSortDirection.Ascending, 2)); await _grid.GridComponent.InitGrouping(payloads); } }