I'm on Blazor Server(.NET 7).
I was trying to follow this example from the documentation but instead of having `Employees` and `Orders` separated I do already have the `Orders` data inside the `EmployeeData` object and when I try to to access that inner data for the inner Grid it doesn't work and outputs a NullReferenceException, all from this code alike:
<SfGrid DataSource="@Employees">
<GridTemplates>
<DetailTemplate>
@{
var employee = (context as EmployeeData);
<SfGrid DataSource="@employee.Orders"></SfGrid>
}
</DetailTemplate>
</GridTemplates>
</SfGrid>
What am I doing wrong? Or is this a limitation of `<DetailTemplate>` that can't function in such a way?
Hi Yevheniy,
We have prepared an sample as per your shared code snippet. But we could not able to replicate the reported issue at our end. Kindly check the below attached code snippet for your reference.
<SfGrid DataSource="@Employees"> <GridTemplates> <DetailTemplate> @{ var employee = (context as EmployeeData); } <SfGrid @ref=Grid[(int)employee.EmployeeID] DataSource="@employee.OrderData" Toolbar="@Toolbaritems" AllowPaging="true" > <GridEvents TValue="Order" OnToolbarClick="@((e)=>ToolbarClickHandler(e, employee.EmployeeID))"></GridEvents> <GridPageSettings PageSize="6"></GridPageSettings> <GridColumns> ... </GridColumns> </SfGrid> </DetailTemplate> </GridTemplates> <GridColumns> ... </GridColumns> </SfGrid>
@code { Dictionary<int?, SfGrid<Order>> Grid = new Dictionary<int?, SfGrid<Order>>();
protected override void OnInitialized() public class EmployeeData { public int? EmployeeID { get; set; } public string FirstName { get; set; } public string Title { get; set; } public string City { get; set; } public string Country { get; set; } public List<Order> OrderData { get; set; } = Orders; } } |
If you still face difficulties then kindly share the below details at your end.
Above requested details will be very helpful in validating the reported query at our end and provide solution as early as possible.
Regards,
Monisha
Ok, I modified the example to match my issue with the NullReferenceException, still didn't figured out what's wrong
Attachment: SyncfusionBlazorApp2_b3346da8.zip
Hi Yevheniy,
After reviewing your information, we have identified that
the issue is due to the missing definition of the GridColumns
tag
inside the child content. We recommend including the highlighted code below to
resolve the issue.
Also we have included modified sample for your reference. Please let us know if you have any concerns.
<ErrorBoundary> <ChildContent>
<SfGrid @ref="Grid[log.TokenId]" DataSource="@log.Actions"> <GridColumns> <GridColumn Field="@nameof(Action.ActionDate)”>
</GridColumns> </SfGrid> </ChildContent> <ErrorContent Context="ex"> <p> @{ var a = ex; @ex.ToString() } </p> </ErrorContent> </ErrorBoundary> |
Please let us know if you have further queries or if you still face difficulties.
Yep, it was this missing piece of tag, thank you.
Hi Yevheniy,
Welcome. Kindly get back to us if you need further assistance. As always we will be happy to help you.