We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Nested data model can't have details datasource from the father object

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?


5 Replies 1 reply marked as answer

MS Monisha Saravanan Syncfusion Team February 1, 2023 09:51 AM UTC


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.


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/SyncfusionBlazorApp2-104099690.zip


<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.


  1. Share us the entire Grid code snippet.
  2. Share us the video demonstration of the issue.
  3. If possible share us the simple issue reproducing sample or try to reproduce the reported issue on the above mentioned sample.


Above requested details will be very helpful in validating the reported query at our end and provide solution as early as possible.


Regards,

Monisha



YH Yevheniy Hvozdikov replied to Monisha Saravanan February 3, 2023 11:07 AM UTC

Ok, I modified the example to match my issue with the NullReferenceException, still didn't figured out what's wrong


Attachment: SyncfusionBlazorApp2_b3346da8.zip



MS Monisha Saravanan Syncfusion Team February 6, 2023 09:20 AM UTC


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.


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/SyncfusionBlazorApp2-1729803993.zip


<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.


Marked as answer

YH Yevheniy Hvozdikov February 7, 2023 11:29 AM UTC

Yep, it was this missing piece of tag, thank you.



MS Monisha Saravanan Syncfusion Team February 8, 2023 10:36 AM UTC

Hi Yevheniy,


Welcome. Kindly get back to us if you need further assistance. As always we will be happy to help you.


Loader.
Live Chat Icon For mobile
Up arrow icon