GridBlazor supports subgrids in CRUD forms. Aside to edit, view and delete fields for an grid item using CRUD, you can add subgrids on the CRUD forms. And these subgrids can also be configured with CRUD support, so you can add, edit, view and delete items that have a 1:N relationship with the parent item.
Fist of all the column definition of the main grid must include the SubGrid
method for those columns that have a 1:N relationship.
c.Add(o => o.OrderDetails).Titled("Order Details").SubGrid(subgrid, ("OrderID", "OrderID"));
If you have more that one subgrid in the CRUD form, you can show all them on a tab group. In this case you have to use an additional paramenter in the SubGrid
method:
c.Add(o => o.OrderDetails).Titled("Order Details").SubGrid("tabGroup1", subgrid, ("OrderID", "OrderID"));
These are the paraments of the Subgrid
method:
Parameter name | Type | Description |
---|---|---|
TabGroup (optional) | string |
Name of the tab group that will show all the subgrids |
SubGrids | Func<object[], bool, bool, bool, bool, Task<IGrid>> |
a funtion that will create the subgrid for each item column |
Keys | params (string, string)[] |
this array contains pairs of strings with the names of the columns that define the 1:N relationship for both tables |
Then you have to define the subgrid that you want to show on the CRUD forms.
Func<object[], bool, bool, bool, bool, Task<IGrid>> subGrids = async (keys, create, read, update, delete) =>
{
var subGridQuery = new QueryDictionary<StringValues>();
Action<IGridColumnCollection<OrderDetail>> subGridColumns = c => ColumnCollections.OrderDetailColumnsCrud(c,
productService.GetAllProducts);
var subGridClient = new GridClient<OrderDetail>(q => orderDetailService.GetOrderDetailsGridRows(subGridColumns, keys, q),
subGridQuery, false, "orderDetailsGrid" + keys[0].ToString(), subGridColumns, locale)
.Sortable()
.Filterable()
.SetStriped(true)
.Crud(create, read, update, delete, orderDetailService)
.WithMultipleFilters()
.WithGridItemsCount();
await subGridClient.UpdateGrid();
return subGridClient.Grid;
};
This function is passed as parameter of the Subgrid
method used on the first step. Of course subgrids must be configured with CRUD support using the Crud()
method of the GridClient
object.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。