This is a migrated thread and some comments may be shown as answers.
Kendo MVC Grid - data binding to dynamic object model
18 Answers 1882 Views
This is a migrated thread and some comments may be shown as answers.
Gunawan Thio
Top achievements
Rank 1
Gunawan Thio asked on 27 Jul 2012, 09:37 AM

Hi there, is there a way to bind Kendo MVC grid to dynamic object (or ExpandoObject)?

18 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 01 Aug 2012, 10:35 AM
Hi Gunawan,

I created a code-library project which you could download and try here.

I hope this helps.

Kind Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Rick
Top achievements
Rank 2
answered on 07 Aug 2012, 11:14 PM
Petur,

    This is an interesting example. I have been working with it to see if I can get the grid wroking with my dynamic objects.

    Unfortunately, unless I'm missing something, your example is really just casting a list of non dynamic objects to a list of dynamic objects. The underlying type remains non-dynamic and the example works. However, if I create actual dynamic objects and try to get them to the grid via ajax, the data does not display.

    For example, if you build the list like this:
var dataList = new List<System.Dynamic.ExpandoObject>();
dynamic row = new System.Dynamic.ExpandoObject();
row.StringValue = "FirstString";
row.IntValue = 1;
dataList.Add(row);
row = new System.Dynamic.ExpandoObject();
row.StringValue = "SecondString";
row.IntValue = 2;
dataList.Add(row);
...

   This gies you a list of dynamic objects, but the grid does not display the values even though it does recognize that there are rows in the datasource.

    I have successfully displayed dynamic data like this on the KendoUI Grid, but only by passing it in as the model data. The part that doesn't work (as far as I can tell) is when I try to use Ajax, which involves serializing and deserializing the data. I realize that the ExpandoObject is not serializable, so in my project I created a serializable dynamic object and tried to use that, but it didn't solve the problem. the data still does not display. It seems that the json data is not deserialized in a way that the grid can use it, even if I specify the fields of the model using .Model().

   I need to use a datasource with Ajax because some of the grids that I will display could have thousands of lines, which will cause a performance problem if is all loaded into the browser.

   Rick.
0
Petur Subev
Telerik team
answered on 11 Aug 2012, 09:33 AM
Hi Rick,

The issue with the ExpandoObject comes when they are being serialized into Json, because it is serialized as KeyValuePairs which is unreadable by the Grid. 
I tried to change the way the dataSource is serialized and it seems it is working fine. However the ToDataSourceResult is not capable of applying filtering over the collection of ExpandoObjects - I am not sure if this could be achieved with CustomBinding.
Please check the attached project and use it as a base point to extend it with custom binding. 
I hope this helps.

Kind Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Chris Williams
Top achievements
Rank 1
answered on 16 Aug 2012, 10:43 PM
I've gotten binding working against a List of ExpandoObjects using server binding.  I've attached an example below.

What I'm having trouble with is sorting against the model.  I see that the GET request comes in with a request parameter like "DataGrid-sort", but I'd like to handle the sorting on the server and return the data without manipulation by Kendo.  I'm currently getting an error that I'm trying to trace down, but it has to do with not being able to find the property on my ExpandoObject. Any ideas appreciated.

Here's my definition:

@(Html.Kendo().Grid(Model.Results)
.Name("DataGrid")           
.Columns(column =>
        {
            foreach (var dataSeries in Model.Report.DataSeriesCollection)
            {
                DataSeries series = dataSeries;
                column
                    .Bound(string.Concat(series.Source, "-", series.Field))
                    .Encoded(false)
                    .Template(t =>
                                  {
                                      IDictionary<String, Object> values = (IDictionary<String, Object>)t;
                                      object value;
                                      values.TryGetValue(string.Concat(series.Source, "-", series.Field), out value);
                                      return Html.WriteValue(values, value, series); //custom formatting
                                  }
                    )
                    .HeaderTemplate(@<text><strong>@series.DisplayName</strong></text>)
                    .Hidden(series.Hidden)                           
                    .Title(series.DisplayName)
                    .Sortable(true)
                    ;
            }                                                               
        })
        .Reorderable(reorder => reorder.Columns(true))
        .Sortable(x => x.Enabled(true)) 
)
0
comgiu
Top achievements
Rank 2
answered on 20 Aug 2012, 05:59 AM
Hi
can you post e zipped example?

thanks
0
Tom
Top achievements
Rank 1
answered on 06 Feb 2013, 07:16 PM
Hi Petur (Subev),
I tired your zipped example and it works fine with a editable view template - you use the line:

.Editable(editable => editable.TemplateName("ProductItem").Mode(GridEditMode.PopUp))

Is it possible, however, to avoid the template and use:

.Editable(editable => editable.Mode(GridEditMode.InCell))

...and possibly:

.ToolBar(toolBar => toolBar.Save())

Whenever I try I get an Invalid Op exception: 

"Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions."

Is there a way round this? If so, then my data definition at all levels can be truly dynamic!  (Or do I have to create a VirtualPathProvider to send a dynamically created ProductItem.cshtml through?)

Thanks,
Tom.


0
Bram
Top achievements
Rank 1
answered on 09 Apr 2013, 10:32 PM
Any answer on this post Tom ?
How do you solved it ?

Paul
0
Peter
Top achievements
Rank 2
answered on 19 Nov 2013, 03:49 PM
Has anyone made any progress on this or come up with a new solution?  I've been able to get my data to show using the IEnumerable<dynamic> , however, I really need to be able to use the inline editing.  
0
David
Top achievements
Rank 1
answered on 09 Apr 2014, 03:01 PM
Hello

I have managed to get the grid working with <dynamic> data type.

So far without editing it has been working great.

I am also trying to use a heirarchy grid.

As soon as I try and expand my heirarchy it complains regarding the primary key field of the level up row that I am trying to expand.

Any help most appreciated.

Kind Regards

David.
0
Petur Subev
Telerik team
answered on 14 Apr 2014, 07:11 AM
Hello David,

Could you please provide us a small project which we can run and see what exactly goes wrong? Feel free to modify my project and send it back.

Regards,
Petur Subev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Aarti
Top achievements
Rank 1
answered on 16 Apr 2014, 03:14 PM
Hi

Can someone please provide me an example for ajax custom binding of kendo grid to dymanic resultset of stored procedure. Scenario is stored procedure returns 2 resultsets - first is schema and second is actual data. But I am not sure how I can bind the data using the schema returned by stored procedure as schema provides the information ablut columns ,their data types etc..
0
Petur Subev
Telerik team
answered on 21 Apr 2014, 11:13 AM
Hello Aarti,

I am afraid this is not possible, you will have to create new dataSource each time based on the schema that you got from the stored procedure call. I would suggest requesting the data with regular $.ajax request and then inside the success callback dynamically create new dataSource with the appropriate schema setting, also you might need to specify the read transport operation as function.

Kind Regards,
Petur Subev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
hkdave95
Top achievements
Rank 2
answered on 21 Apr 2014, 01:30 PM
Hi All

Petur - I think I have a solution using DataSets.

I will try and create a code example and post in the last two weeks of May when I will have some time.

Kind Regards

David
0
hkdave95
Top achievements
Rank 2
answered on 21 Apr 2014, 04:20 PM
Hi All

Update  - The solution is for a grid with columns of a dynamic nature using ASP.NET MVC methodology and C#.

Just in case you will waiting with baited breath for something more jquery in nature.

Thank you

David
0
Petur Subev
Telerik team
answered on 24 Apr 2014, 10:12 AM
Hello Gunawan,

Feel free to submit your sample as a code library project which the community can make use of.

http://www.telerik.com/support/code-library/aspnet-mvc/grid

Kind Regards,
Petur Subev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
hkdave95
Top achievements
Rank 2
answered on 19 Jun 2014, 03:30 AM
Hi All

Sorry, I had a brilliant holiday in May and did not get around to posting a code sample.

This shall have to wait as the boss has me working fairly flat out on loads of issues that keep cropping up.

David
0
Vince
Top achievements
Rank 1
answered on 27 Feb 2015, 12:30 AM
Hi David were u ever able to get a solution to this? If u could post a sample it would be much appreciated?

Vince.
0
hkdave95
Top achievements
Rank 2
answered on 15 Jul 2016, 06:01 PM

Hello Vince

I got it working. However, I had to modify the Kendo.Mvc.dll.

If you really want me to share the result with you email me at david@dar-jader.com

I have not got enough time to put the solution into a code sample and package for Telerik.

David

Tags
Grid
Asked by
Gunawan Thio
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Rick
Top achievements
Rank 2
Chris Williams
Top achievements
Rank 1
comgiu
Top achievements
Rank 2
Tom
Top achievements
Rank 1
Bram
Top achievements
Rank 1
Peter
Top achievements
Rank 2
David
Top achievements
Rank 1
Aarti
Top achievements
Rank 1
hkdave95
Top achievements
Rank 2
Vince
Top achievements
Rank 1
Share this question
or