Grid Foreign Key Column Not Showing

1 Answer 11 Views
Grid
Mehmet
Top achievements
Rank 1
Iron
Mehmet asked on 15 Apr 2024, 12:07 PM

Hello,

I want to show, group and filter the Id field on one of the grid columns by connecting it to the Enum side.

I used ForeignKey column but it doesn't show the data.

The request is being sent. data is returning. But it doesn't show.

Important Note: I don't use inline editing on the grid. It'll only show.

What's wrong?

Result SET
{
    "Data": [
        {
            "LogoUrl": "",
            "ParentCompany": null,
            "ParentCompanyId": 0,
            "CompanyType": 10,
            "CompanyTypeId": 10,
            "Title": "POL & PAK LTD",
            "Code": "12688900",
            "PostCode": "ST1 4NP",
            "Address": "10 Harcourt Street, Stoke-On-Trent, England, ST1 4NP",
            "ShortNotes": "12688900 - Incorporated on 22 June 2020",
            "VatNumber": null,
            "ExemptVat": false,
            "EoriNumber": null,
            "RegisterNumber": "12688900",
            "CreditLimit": 0.00000,
            "DiscountRate": 0.00000,
            "CreditTerm": null,
            "CreditTermId": 0,
            "Longitude": null,
            "Latitude": null,
            "Status": "Active",
            "StatusId": 10,
            "Id": 1
        }
    ],
    "Total": 1,
    "AggregateResults": null,
    "Errors": null
}

Column
 columns.ForeignKey(p => p.CreditTermId, ds => ds.Read(r => r.Action("GetCreditTerms", "ErpCommon")), "CreditTermId", "CreditTermName").Title("CreditTerm"); 

Endpoint
 public async Task<IActionResult> GetCreditTermsAsync()
 {
     var model = new List<ErpCreditTermViewModel>();

     var availibleCreditTerms = await _erpCreditTermService.GetCreditTermsAsync();
     foreach (var creditTerm in availibleCreditTerms)
     {
         var erpCreditTermViewModel = await _erpCreditTermModelFactory.PrepareCreditTermViewModelAsync(creditTerm);
         model.Add(erpCreditTermViewModel);
     }

     return Json(model);
 }

1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 18 Apr 2024, 07:40 AM

Hi Mehmet,

I noticed that there is no active license associated with your account. Which limits our support service overall. In this regard, I would advise purchasing a new license, in order to get a hold of the latest bug fixes, enhancements, and support service. More information regarding the available purchase plans is available here:

Regardless, I want to help you unravel this further. I have created a proof-of-concept sample for you to examine further. Here is how the different logical compartments are incorporated:

Grid Columns:

.Columns(columns =>
{
    columns.ForeignKey(o => o.CreditTermId, ds => ds.Read(r => r.Action("GetCreditTerms", "ErpCommon")), "CreditTermId", "CreditTermName");
})

Model:

public class Order
{
    public int OrderId { get; set; }
    public string OrderName { get; set; }
    public CreditTypes CreditTermId { get; set; } // Foreign Key
}

Enum:

public enum CreditTypes
{
    None,
    Some
}

GetCreditTermsAsync Method:

public async Task<List<ErpCreditTermViewModel>> GetCreditTermData()
{
    var data = Enumerable.Range(0, 2)
        .Select(i => new ErpCreditTermViewModel
        {
            CreditTermId = i,
            CreditTermName = "TermName" + i
        })
        .ToList();

    return Task.FromResult(data).GetAwaiter().GetResult();
} 

public async Task<IActionResult> GetCreditTermsAsync()
{
    var model = await Task.Run(GetCreditTermData);

    return Json(model);
}

Attached is a runnable sample for you to examine further.

Kind Regards,
Alexander
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.
Tags
Grid
Asked by
Mehmet
Top achievements
Rank 1
Iron
Answers by
Alexander
Telerik team
Share this question
or