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

Grid not showing Data after adding GridForeignColumn on include table

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.

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



3 Replies 1 reply marked as answer

MS Monisha Saravanan Syncfusion Team January 19, 2023 01:34 PM UTC


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.


  1. Share us the model class of Grid and Foreign key column to proceed further at our end.
  2. Share us the video demonstration of the issue.
  3. Share us the Nuget version used at your end.
  4. If possible share us an simple issue reproduceable 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

If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Marked as answer

LA Larry January 20, 2023 04:55 AM UTC

Thank you for your reply.   I decided to combine both tables into a viewModel.   This resolved my issue in this case.

thanks again.



MS Monisha Saravanan Syncfusion Team January 23, 2023 03:58 AM UTC

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


Loader.
Up arrow icon