Dropdown from Enum in Grid

Hi all,

I am trying to bind an enum list to a Grid control in Blazor Server-side, but I am having difficulty. I have been through different iterations, but here is what I am trying now:

<SfGrid DataSource="@DeliverySystemTypes" AllowPaging="true" AllowSelection="true"
                            Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel"})">
                        <GridEvents OnActionBegin="ActionBeginDeliverySystemType" OnActionComplete="ActionCompleteDeliverySystemType" TValue="DeliverySystemType"></GridEvents>
                        <GridPageSettings PageSize="20"></GridPageSettings>
                        <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Normal" ShowConfirmDialog="true"
                                            NewRowPosition="NewRowPosition.Top"
                                            ShowDeleteConfirmDialog="true"></GridEditSettings>
                        <GridColumns>
                            <GridColumn Field=@nameof(DeliverySystemType.DeliverySystemTypeID) HeaderText="HospitalUser ID" IsPrimaryKey="true" Visible="false"></GridColumn>
                            <GridForeignColumn Field=@nameof(DeliverySystemType.Type) ForeignKeyField="Id" ForeignKeyValue="Text" ForeignDataSource="@Types" HeaderText="Type"></GridForeignColumn>
                            <GridColumn Field=@nameof(DeliverySystemType.DeliverySystemTypeName) HeaderText="Name"></GridColumn>
                            <GridColumn Field=@nameof(DeliverySystemType.Manufacturer) HeaderText="Manufacturer"></GridColumn>
                            <GridColumn Field=@nameof(DeliverySystemType.Model) HeaderText="Model"></GridColumn>
                        </GridColumns>
                    </SfGrid>

And the model:

    private List<DeliverySystemType>? DeliverySystemTypes;
    private List<DeliverySystemLabelModel> Types;


    public class DeliverySystemLabelModel
    {
        public DeliverySystemLabel Id { get; set; }
        public string Text { get; set; }
    }


    protected override async Task OnInitializedAsync()
    {
        DeliverySystemTypes = await DeliverySystemTypeService.GetDeliverySystemTypeDetails();


        Types = new List<DeliverySystemLabelModel>();
        Types.Add(new DeliverySystemLabelModel { Id = DeliverySystemLabel.LINAC, Text = "LINAC" });
        Types.Add(new DeliverySystemLabelModel { Id = DeliverySystemLabel.HDR, Text = "HDR" });
        Types.Add(new DeliverySystemLabelModel { Id = DeliverySystemLabel.Co60, Text = "Co-60" });
        Types.Add(new DeliverySystemLabelModel { Id = DeliverySystemLabel.Superficial, Text = "Superficial" });
    }

Where the enum is DeliverySystemLabel. 


Does anyone have a good way to bind an enum directly to a Grid control to give the DropDown options. The is saving via EF Core, .NET 6 as well.




1 Reply

MS Monisha Saravanan Syncfusion Team April 18, 2022 12:24 PM UTC

Hi Johnathan,


Greetings from Syncfusion support.


We have analyzed your query and we suspect that you are facing difficulties in binding Enum type column with foreign key field. We have prepared an sample based on your shared information and it is working fine at our end. Kindly download and refer the below attached sample from your side.


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/BlazorApp1-1242812598.zip


If the reported issue still persist or if we misunderstood your query kindly get back to us with an issue reproduceable sample or try to reproduce the issue on the above sample and share with us for further analysis.


Regards,

Monisha


Loader.
Up arrow icon