The Grids Data source uses @ents tolist.
var ents = db.Ents.Include("EntDem").Where(e => e.DeleteSts == false && e.Typ == typ);
return await ents.ToListAsync(); //returns fields from both Ent Table and EntDem table.
The first GridForeignColumn in grid works and displays data. When I add the 2nd GridForeignColumn via the joined table EntDem the grid shows no data.
<SfGrid ID="Grid" DataSource="@ents" @ref="DefaultGrid" Toolbar="@Toolbaritems" AllowExcelExport="true" AllowPdfExport="true" AllowPaging="true" AllowSorting="true" AllowFiltering="true" AllowGrouping="true"> <GridEvents OnToolbarClick="ToolbarClickHandler" TValue="Ent" RowSelected="RowSelectHandler" OnRecordDoubleClick="RecordDoubleClickHandler"></GridEvents> <GridColumns> <GridPageSettings PageSizes="pagerItemsPerPage" PageSize="15"></GridPageSettings> <GridFilterSettings Mode="FilterBarMode.Immediate" ImmediateModeDelay="200"> </GridFilterSettings> </GridColumns> <GridColumns> <GridColumn Field="@nameof(Ent.EntId)" HeaderText="Id" TextAlign="TextAlign.Center" Width="50"> </GridColumn> <GridColumn Field="@nameof(Ent.FirstName)" HeaderText="First Name" TextAlign="TextAlign.Left" Width="100"> </GridColumn> <GridColumn Field="@nameof(Ent.LastName)" HeaderText="Last Name" TextAlign="TextAlign.Left" Width="100"> </GridColumn> <GridColumn Field="@nameof(Ent.MiddleName)" HeaderText="Middle Name" TextAlign="TextAlign.Left" Width="100"> </GridColumn> <GridColumn Field="@nameof(Ent.NickName)" HeaderText="Nick Name" TextAlign="TextAlign.Left" Width="100"> </GridColumn> <GridForeignColumn Field="@nameof(Ent.ActStsId)" HeaderText="Status" ForeignDataSource="@mcrs" ForeignKeyField="McrId" ForeignKeyValue="Descr" Width="100"> </GridForeignColumn> <GridForeignColumn Field="@nameof(Ent.EntDem.GenderId)" HeaderText="Gender" ForeignDataSource="@mcrs" ForeignKeyField="McrId" ForeignKeyValue="Descr" Width="100"> </GridForeignColumn> <GridColumn Field="@nameof(Ent.PassWord)" HeaderText="Password" TextAlign="TextAlign.Left" Width="100"> </GridColumn> <GridColumn Field="@nameof(Ent.Email)" HeaderText="Email" TextAlign="TextAlign.Left" Width="100"> </GridColumn> <GridColumn Field="@nameof(Ent.Comment)" HeaderText="Comment" TextAlign="TextAlign.Left" Width="100"> </GridColumn> </GridColumns> </SfGrid>
Is there an issue with how I setup the 2nd GridForeignColumn of the joined table? I did test and data was being returned to ents tolist.
Thanks for your assistance.
Hi Larry,
We suspect that you are using complex column for the second foreign key column. We suggest you to use the dot(.) operator in the column field for complex columns by using the below way. Kindly check the below attached code snippet and documentation for your reference.
<SfGrid DataSource="@Employees" Height="315"> <GridColumns> <GridColumn Field="Category.Description" HeaderText="Last Name"Width="130"></GridColumn> </GridColumns> </SfGrid>
@code{
public class EmployeeData {
public virtual Category Category { get; set; } }
public class Category { public string Description { get; set; }
} } |
If you need to use nameof operator then kindly check the notes section from the below documentation.
Reference: https://blazor.syncfusion.com/documentation/datagrid/columns#complex-data-binding
https://blazor.syncfusion.com/documentation/datagrid/columns#foreign-key-column---local-data
If you still face difficulties then kindly share the below details to proceed further at our 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
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Thank you for your reply. I decided to combine both tables into a viewModel. This resolved my issue in this case.
thanks again.
Hi Larry,
Welcome. We are glad to hear that the reported issue has been resolved. Kindly get back to us if you need further queries. As always we will be happy to help you.
Regards,
Monisha