Completed
Last Updated: 24 Jun 2020 07:26 by ADMIN
Release 2.15.0
Paul
Created on: 16 Sep 2019 23:01
Category: Grid
Type: Feature Request
21
Please add support for binding grids to dynamic ExpandoObject

Because the shape of our business objects is not something your grid is easily bound to, we are attempting to generate ExpandoOjbects on the fly and bind to them.  In the picture below you can see that Id is not binding correctly.  Name is showing up because a column Template was used and that seems to work fine.  However, when attempting to use an EditorTemplate we get the RuntimeBinderException shown below.

 

 

 

 

 

@page "/dynamic-vendor"
@using System.Dynamic
@using Telerik.Blazor.Components.Grid

<div style="width: 800px; overflow-x: auto; overflow-y:hidden; border: 1px solid red; height:400px">
    <TelerikGrid Data="@expandoVendors" EditMode="inline" Pageable=true PageSize=10 SelectionMode="Telerik.Blazor.GridSelectionMode.Multiple">
        <TelerikGridColumns>
            <TelerikGridCommandColumn width="100">
                <TelerikGridCommandButton Command="Edit" Icon="edit">Edit</TelerikGridCommandButton>
                <TelerikGridCommandButton Command="Update" Icon="save" ShowInEdit="true">Update</TelerikGridCommandButton>
                <TelerikGridCommandButton Command="Cancel" Icon="cancel" ShowInEdit="true">Cancel</TelerikGridCommandButton>
            </TelerikGridCommandColumn>
            <TelerikGridColumn Field="Id"></TelerikGridColumn>
            <TelerikGridColumn Field="Name" Title="Name" Editable="true">
                <Template>
                    @{
                        dynamic v = context as ExpandoObject;
                        <span style="white-space:nowrap">@(v.Name)</span>
                    }
                </Template>
                <EditorTemplate>
                    @{
                        dynamic v = context as ExpandoObject;
                        <input type="text" bind="@(v.Name)" />
                    }
                </EditorTemplate>
            </TelerikGridColumn>
        </TelerikGridColumns>
    </TelerikGrid>
</div>

@functions {

    List<ExpandoObject> expandoVendors { get; set; }

    protected override async Task OnInitializedAsync()
    {
        expandoVendors = new List<ExpandoObject>();
        var v1 = new ExpandoObject();
        v1.TryAdd("Id", "1");
        v1.TryAdd("Name", "Google");
        expandoVendors.Add(v1);

        var v2 = new ExpandoObject();
        v2.TryAdd("Id", "2");
        v2.TryAdd("Name", "Amazon");
        expandoVendors.Add(v2);
    }

}
5 comments
ADMIN
Marin Bratanov
Posted on: 07 Apr 2020 07:02

Hello,

@Robert: At the moment, the tentative plan is still mid-May. It is high on our priority list.

@cmarsh: the expandos are not high on the priority list, although other things we're working on may either implement this, or make it unnecessary (we're working on autogenerating columns from the model fields).

 

Regards,
Marin Bratanov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Robert
Posted on: 06 Apr 2020 20:37
@cmarsh  I was asking the Telerik team  :)  I would like this feature as well so I can get rid of reflection..
cmarsh
Posted on: 06 Apr 2020 20:35
Thank you - that's great news. We can move forward with our project then.
Robert
Posted on: 06 Apr 2020 20:32
ADMIN
Marin Bratanov
Posted on: 18 Sep 2019 07:04

Hello Paul,

You may also want to Vote and Follow this, in case it would serve you as another data source with dynamic set of fields (columns): https://feedback.telerik.com/blazor/1418456-bind-to-datatable. I suspect it may be implemented sooner, as it may have a larger audience (e.g., people migrating from WebForms). Both concepts will require detailed research first, though, and my best advice is to Follow them to get status notifications.

In the meantime, I have seen similar errors when the model fields don't have both a getter and a setter, so something similar may be happening with the expando objects. I am note completely sure if you can do anything about it, however, and perhaps for this to work, we may need to take explicit steps to clone those objects. In the meantime, I can suggest you look into using an external editor for the grid: https://demos.telerik.com/blazor-ui/grid/editing-custom-form.

 

Regards,
Marin Bratanov
Progress Telerik

 UI for Blazor