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

issue related to adding foreign key field to grid

Hello,

I am trying to get a foreign key filed name into the grid below. However, I received an error:  The attribute names could not be inferred from bind attribute 'bind-Value'. Bind attributes should be of the form 'bind' or 'bind-value' along with their corresponding optional parameters like 'bind-value:event', 'bind:format' etc.





 <SfGrid SelectedRowIndex=1 DataSource="@GridData" Toolbar="@ToolbarItems"

                    ContextMenuItems="@ContextMenuItems"

                    AllowFiltering="true" AllowExcelExport=true AllowPaging="true" AllowSorting=true>

                <GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="Syncfusion.Blazor.Grids.EditMode.Dialog"></GridEditSettings>

                <GridPageSettings PageSize="10"></GridPageSettings>

                <GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Excel"></GridFilterSettings>

            

                <GridEvents OnActionBegin="ActionBeginHandler" TValue="ContactList"></GridEvents>

                <GridColumns>

                    <GridColumn Field=@nameof(ContactList.ID) TextAlign="TextAlign.Center" IsPrimaryKey=true IsIdentity=true HeaderText="ID" Width="6"> </GridColumn>

                    <GridColumn Field=@nameof(ContactList.Names) TextAlign="TextAlign.Left" HeaderText="Contact Name" Width="10"></GridColumn>

                    <GridColumn Field=@nameof(ContactList.OrganizationID) DefaultValue="99" Width="10"></GridColumn>

                    <GridForeignColumn Field=@nameof(ContactList.OrganizationID) HeaderText="Org Name" ForeignKeyValue="Organization" ForeignDataSource="@OrgDataSource" Width="15">

                        <FilterTemplate>

                            <SfDropDownList Placeholder="Organization Name" ID="OrgName" @bind-Value="@((context as PredicateModel<string>).Value)" TItem="tblOrganisation" TValue="string" DataSource="@OrgDataSource">

                                <DropDownListFieldSettings Value="Organization" Text="Organization"></DropDownListFieldSettings>

                            </SfDropDownList>

                        </FilterTemplate>

                    </GridForeignColumn>

                    <GridColumn Field=@nameof(ContactList.Nationality) DefaultValue="@nationality" TextAlign="TextAlign.Center" Width="8"></GridColumn>

                    <GridColumn Field=@nameof(ContactList.DOB) Format="dd-MMM-yyyy" TextAlign="TextAlign.Center" Type="ColumnType.DateTime" EditType=EditType.DatePickerEdit Width="8"></GridColumn>

                    <GridColumn Field=@nameof(ContactList.DateOfPassing) HeaderText="Date of Passing" Format="dd-MMM-yyyy" TextAlign="TextAlign.Center" Type="ColumnType.DateTime" EditType=EditType.DatePickerEdit Width="8"></GridColumn>

                    <GridColumn Field=@nameof(ContactList.Age) HeaderText="Age" TextAlign="TextAlign.Center" Width="10" Type="ColumnType.String">

                        <Template>

                            @{

                                var contactList = (context as ContactList);

                                var age = CalculateAge(contactList.DOB, contactList.DateOfPassing);

                                <div>@age</div>

                            }

                        </Template>

                        <EditTemplate Context="X">

                        </EditTemplate>

                    </GridColumn>

                    <GridColumn Field=@nameof(ContactList.Email) Width="10" Visible=false ShowInColumnChooser=true></GridColumn>

                    <GridColumn Field=@nameof(ContactList.Phone) Width="10"></GridColumn>

                </GridColumns>

                <GridSortSettings>

                    <GridSortColumns>

                        <GridSortColumn Field="Names" Direction="SortDirection.Ascending"></GridSortColumn>

                    </GridSortColumns>

                </GridSortSettings>

            </SfGrid>

        </div>

    </div>

</div>

@code {

    SfGrid<ContactEducation> GridEducation;

 

    public string[] ToolbarItems = new string[] { "Add", "Edit", "Delete", "Cancel", "Update", "ExcelExport", "Search", "Print", "ColumnChooser" };

    public string[] ContextMenuItems = new string[] { "Group", "Ungroup", "ColumnChooser", "Filter" };

    private string nationality = "Khmer";


    public Query GetContactEducation(ContactList value)

    {

        return new Query().Where("ContactID", "equal", value.ID);

    }


   


    public IEnumerable<ContactList> GridData { get; set; }

   

    public IEnumerable<tblOrganisation> OrgDataSource { get; set; }


    protected override void OnInitialized()

    {

        GridData = MyDBServices.GetContactList();

     

        OrgDataSource = MyDBServices.GetOrganisationList();

    }


Please help to correct the problem


Regards


Sao



3 Replies

NP Naveen Palanivel Syncfusion Team April 4, 2023 04:30 PM UTC

Hi Sao,


We checked your query and we suspect  having trouble with the Gridforeigncolumn with dropdown component in filtertemplate. We created a simple FilterTemplate with a Foreign Column as an example. Please see the code snippet and sample for further information.

  <GridForeignColumn Field=@nameof(Order.EmployeeID) HeaderText="Employee Name" ForeignKeyValue="FirstName" ForeignDataSource="@Employees" Width="150">

             <FilterTemplate>

                <SfDropDownList Placeholder="EmployeeID" ID="EmployeeID" @bind-Value="@((context as PredicateModel<string?>).Value)" TItem="EmployeeData" TValue="string" DataSource="@(Employees)">

                    <DropDownListFieldSettings Value="FirstName" Text="FirstName"></DropDownListFieldSettings>

                </SfDropDownList>

            </FilterTemplate>

 

        </GridForeignColumn>



Please let us know if you have any concerns.


Regards,

Naveen Palanivel


Attachment: Blazor_Foreign_5b93679c.zip


SA Sao April 5, 2023 02:34 AM UTC

Dear Naveen,


I am sorry that I am not making myself clear,


My issue is when I add a new record, I can't select data from the foreign table (in this case is the Organisation filed).


How do you allow new record entries by allowing users to select Organisation? 


Best regards


Sao



NP Naveen Palanivel Syncfusion Team April 7, 2023 03:27 AM UTC


Hi Sao,


We checked your query, we prepared sample and check the reported problem. But report issue does not occurs at our end. Please refer the attached sample for your reference.


If the reported issue still reproduced then kindly share the below details to validate further at our end.


  1. Share us the video demonstration of the issue in provided sample.
  2. If possible share us an simple issue reproduceable sample or try to modify the above mentioned sample.


The above-requested details will be very helpful for us to validate the reported query at our end and provide the solution as early as possible


Regards,

Naveen Palanivel


Attachment: Blazor_Forgein_8c598b92.zip

Loader.
Up arrow icon