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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How To Create A Foreign Key Dropdown Using A Web API Instead Of The Viewbag

Thread ID:

Created:

Updated:

Platform:

Replies:

144645 May 15,2019 03:44 PM UTC May 17,2019 05:50 AM UTC ASP.NET Core - EJ 2 3
loading
Tags: DataGrid
danacon
Asked On May 15, 2019 03:44 PM UTC

Hi,

I am looking to populate my grid using web api calls (webapiadapter) rather than the viewbag method and so i would like to also get the foreign key data for the dropdown as well using the web api method. The only sample i can find uses another property on the viewbag (e.g. viewbag.foreignkeydata in addition to viewbag.datasource).

Do you have any guidance or samples for achieving this?

Many Thanks

Thavasianand Sankaranarayanan [Syncfusion]
Replied On May 16, 2019 10:25 AM UTC

Hi danacon, 
 
Greetings from Syncfusion support. 
 
Query: I am looking to populate my grid using web api calls (webapiadapter) rather than the viewbag method and so i would like to also get the foreign key data for the dropdown as well using the web api method. The only sample i can find uses another property on the viewbag (e.g. viewbag.foreignkeydata in addition to viewbag.datasource). Do you have any guidance or samples for achieving this? 
 
We have validated your query and created sample based on your requirement. Here, we have bind both grid data source and foreign key column dataSource as remote data in WebApiAdaptor. Please find the below code example and sample for your reference. 
 
[code example] 
 
<ejs-grid id="Grid" allowPaging="true" enablePersistence="false" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel","Search" })"> 
    <e-data-manager id="myData" url="/api/Orders" adaptor="WebApiAdaptor" crossDomain="true"></e-data-manager> 
    <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true"></e-grid-editSettings> 
    <e-grid-columns> 
        <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="120"></e-grid-column> 
        <e-grid-column field="EmployeeID" headerText="Employee Name" foreignKeyField="EmployeeID" foreignKeyValue="CustomerID" dataSource="@(new Syncfusion.EJ2.DataManager() { Url = "/api/Employee", Adaptor = "WebApiAdaptor"})" width="150"></e-grid-column> 
        <e-grid-column field="ShipCity" headerText="Ship City" width="170"></e-grid-column> 
        <e-grid-column field="ShipCountry" headerText="Ship Country" template="<a>${ShipCountry}</a>" width="150"></e-grid-column> 
    </e-grid-columns> 
</ejs-grid> 
 
[Route("api/Employee")] 
 
        public object Get() 
        { 
                var data1 = EmpoyeeDetails.GetAllRecords().ToList(); 
                return  new { Items = data1, Count = data1.Count() }; 
       } 
 
 
Please get back to us if you need further assistance. 
 
Regards, 
Thavasianand S.

danacon
Replied On May 16, 2019 04:05 PM UTC

Hi Thavasianand, many thanks for this! i didn't realise you could setup a new datasource at field level, that will be very useful :)

I will download your sample and test it out, then if i have any more questions i will reply here in this thread

cheers
dan


Thavasianand Sankaranarayanan [Syncfusion]
Replied On May 17, 2019 05:50 AM UTC

Hi Dan, 

Thanks for your update. 

We will wait to hear from you. 

Regards, 
Thavasianand S. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon