26 lines
870 B
Markdown
26 lines
870 B
Markdown
# MgGrid — Master-Detail
|
|
|
|
> Part of the MgGrid system. See `MGGRID.md` for overview and component hierarchy.
|
|
|
|
## How It Works
|
|
|
|
1. `MgGridBase.BuildRenderTree` wraps content in `CascadingValue<IMgGridBase>`
|
|
2. Child grids receive this via `[CascadingParameter] IMgGridBase? ParentGrid`
|
|
3. `IsMasterGrid` = `ParentDataItem == null`
|
|
4. `GetRootGrid()` walks the `ParentGrid` chain to find the topmost grid
|
|
|
|
## Detail Grid Setup
|
|
|
|
```razor
|
|
<DetailRowTemplate>
|
|
@{
|
|
var parent = (ParentEntity)context.DataItem;
|
|
<GridChildEntity ParentDataItem="@parent"
|
|
KeyFieldNameToParentId="ParentEntityId"
|
|
ContextIds="@(new object[] { parent.Id })" />
|
|
}
|
|
</DetailRowTemplate>
|
|
```
|
|
|
|
When `ParentDataItem` is set and `KeyFieldNameToParentId` is provided, new items automatically get their parent FK set via reflection.
|