<SfGrid DataSource="@customers" AllowPaging="true" AllowGrouping="true" Toolbar="@toolbar">
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings>
<GridPageSettings PageSize="5"></GridPageSettings>
<GridFilterSettings Type = "Syncfusion.Blazor.Grids.FilterType.Menu"></GridFilterSettings>
<GridEvents OnActionBegin="ActionBeginHandler" OnActionComplete="ActionCompleteHandler" TValue="Customer"></GridEvents>
<GridColumns>
<GridColumn IsPrimaryKey=true Field="@nameof(Customer.Id)" Width="40px" Format="d" HeaderText="ID" />
<GridColumn Field="@nameof(Customer.Name)" Width="80px" HeaderText="Name" />
<GridColumn Field="@nameof(Customer.Age)" Width ="60px" HeaderText="Age" />
<GridColumn Field="@nameof(Customer.CreatedDate)" Width="60px" Format="d" HeaderText="Created Date" />
<GridColumn Field="@nameof(Customer.ShoeSize)" Width="60px" HeaderText="Shoe Size" />
</GridColumns>
</SfGrid>
This works fine without the closing tags. But if I try to add a <GridForeignColumn> I will get an error since the GridColumns aren't closed. If i try to just add the </GridColumn> I get errors for each. Any help in what I am missing would be appreciated. Thanks
Columns>
Sorry I see that I already have them closed /> rather then </GridColumn>
Hi Randy,
Greeting from Syncfusion support.
To add a <GridForeignColumn> in Syncfusion Blazor grid, you can simply add it within the <GridColumns> element, Kindly refer the below code snippet and UG documentation for your reference.
<GridColumns>
<GridColumn IsPrimaryKey=true Field="@nameof(Customer.Id)" Width="40px" Format="d" HeaderText="ID" /> <GridColumn Field="@nameof(Customer.Name)" Width="80px" HeaderText="Name" /> <GridColumn Field="@nameof(Customer.Age)" Width ="60px" HeaderText="Age" /> <GridColumn Field="@nameof(Customer.CreatedDate)" Width="60px" Format="d" HeaderText="Created Date" /> <GridColumn Field="@nameof(Customer.ShoeSize)" Width="60px" HeaderText="Shoe Size" />
<GridForeignColumn Field="@nameof(Customer.Country)" Width="100px" HeaderText="Country" ForeignKeyField="@nameof(Customer.CountryId)" DataSource="@countries" TextAccessor="@((object data) => ((Country)data).Name)"> </GridForeignColumn>
</GridColumns> |
Note that the <GridForeignColumn> element should be closed with a corresponding closing tag, just like any other Blazor component. Also, make sure that the necessary properties like ForeignKeyField,ForeignDataSource, and ForeignKeyValue are provided appropriately.
https://blazor.syncfusion.com/documentation/datagrid/columns#foreign-key-column
Kindly get back to us if you have further queries.
Regards,
Bala.