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
close icon

Query in grid doesn't compile

I'm trying to populate a grid inside a grid column using the Query attribute. But I keep getting the compiling error " The name 'nameof' does not exist in the current context". The code compiles properly if I don't use the Query attribute.


First attempt:


<SfGrid DataSource="@baseRoles" AllowSorting="true" AllowTextWrap="true" AllowFiltering="false" AllowSelection="false" Toolbar="@(new List<string>() { "Cancel", "Update" } )">

    <GridEditSettings AllowAdding="false" AllowEditing="true" AllowDeleting="false" AllowEditOnDblClick="true" ShowDeleteConfirmDialog="true" />

    <GridSelectionSettings Mode="Syncfusion.Blazor.Grids.SelectionMode.Cell" />

    <GridSelectionSettings CheckboxOnly="false" />

    <GridColumns>

        <GridColumn Field="@nameof(BaseRole.BaseRoleID)" IsPrimaryKey="true" HeaderText="BaseRole ID" Visible="false" />

        <GridColumn Field="@nameof(BaseRole.AppID)" HeaderText="Application ID" Visible="false" />

        <GridColumn Field="@nameof(BaseRole.RoleName)" HeaderText="App Role" AllowEditing="false" AutoFit="true" />

        <GridColumn Field="@nameof(RoleGridRole.CustomRoleName)" HeaderText="Custom Role" AutoFit="true">

            <Template>

                @{

                    var row = (context as BaseRole);

                }

                <SfGrid DataSource="@customRoles" Query="GetCustomRoles(row.BaseRoleID)" Width="200" RowHeight="15" AllowFiltering="false">

                    <GridColumns>

                        <GridColumn Field="@nameof(CustomRole.CustomRoleID)" Visible="false" />

                        <GridColumn Field="@nameof(CustomRole.BaseRoleID)" Visible="false" />

                        <GridColumn Field="@nameof(CustomRole.CustomRoleName)" HeaderText="" AllowEditing="true" AutoFit="true" />

                    </GridColumns>

                </SfGrid>

            </Template>

        </GridColumn>

    </GridColumns>

</SfGrid>


public class BaseRole

{

    public int BaseRoleID { get; set; }

    public int AppID { get; set; }

    public string RoleName { get; set; }

}


public class CustomRole

{

    public int CustomRoleID { get; set; }

    public int BaseRoleID { get; set; }

    public string CustomRoleName { get; set; }

}


Second attempt:


<SfGrid DataSource="@customRoles" Query="@GetCustomRoles(row.BaseRoleID)" Width="200" RowHeight="15" AllowFiltering="false">


private List GetCustomRoles(int baseRoleId)

{

    var roles = this.customRoles.Where(r => r.BaseRoleID == baseRoleId).ToList();

    return roles;

}

Both attempts fail to compile with the error I mentioned above. What am I doing wrong?



1 Reply

NP Naveen Palanivel Syncfusion Team January 29, 2023 03:28 PM UTC

Hi Andy,


Thank you for reaching out to Syncfusion support,


We have analyzed your query ,we suspect you want to  display child grid inside the ever row of grid. We have already detailly discussed about this topic in our UG documentation. Kindly refer the documentation link shared.


Refer our UG documentation for your reference :

https://blazor.syncfusion.com/documentation/datagrid/detail-template#rendering-custom-component


Please let us know if you have any concerns.


Regards,

Naveen Palanivel


Loader.
Live Chat Icon For mobile
Up arrow icon