This question is locked. New answers and comments are not allowed.
There seems to be many questions relating to binding on a DataTable, but none that I could find touch on my exact situation.
I'm currently ajax binding on a list of objects like such:
And with a view like such:
This works great and all as I'm able to sort, group, and all the above.
My situation is I have many properties on MyObject and some edges cases are popping up that are yielding a couple megabytes of response data. The reason being there are many hidden columns that are situational dependent that a user can right-click/show. The problem is all these extra hidden columns are getting response data. And since the act of grouping and ungrouping fetches for data anyways, why does all the extra data have to come with it?
If I could have only the data returned that is necessary to populate the visible columns plus say a couple that I could mark somehow with a custom attribute, that would immensely help cut back on the size of the returned data.
So I took to converting my list of objects to a DataTable that I could then conditionally add columns + data for and then feed that to the GridModel. This worked well up until trying to group by a column that is in a nested object such as o.MyObject2.Color.
I run into this exception:
Property with specified name: MyObject2.Color cannot be found on type: System.Data.DataRowView
I guess this makes sense, but how do I overcome this? When I use Object Shredder, it sets each property of MyObject loosely typed such as ["Name"] which is a string and ["MyObject2"] which is MyObject2. But everything past ["MyObject2"] is strongly typed: (dataRow["MyObject2"] as MyObject2).Color. And this is where is gets over my head.
Is there another way to overcome my initial issue of all that extra data being sent that isn't used? Or, is there any advice with the DataTable bit? I've also tried converting the DataTable to a IEnumerable<Dynamic> with no such luck. The serialized Json is quite empty. I've also tried flattening all nested objects such as having datarow["MyObject2.Color"] as string, but this wreaks havok when referencing this column in JavaScript so I had to go with an underscore delimiter ["MyObject2_Color"] but this really screws up binding Columns in the UI. There has to be a way!
I'm currently ajax binding on a list of objects like such:
public class MyObject{ public string Name { get; set; } public string Something1{ get; set; } public string Something2{ get; set; } public string Something3 { get; set; } public MyObjectMyObject2 { get; set; }} public class MyObject2{ public string Color { get; set; } public string Something4 { get; set; }} [GridAction]public ActionResult GetData(){ var data = QueryDatabaseAndInstantiateAListOfMyObjects(); return View(new GridModel(data ));}And with a view like such:
<%= Html.Telerik().Grid<MyObject>() .DataBinding(dataBinding => dataBinding.Ajax().Select("GetData", new { action = "GetData" })) .Name("Grid1") .Columns(columns => { columns.Bound(o => o.Name).Title("Name1"); columns.Bound(o => o.MyObject2.Color).Title("Color"); columns.Bound(o => o.Something1).Hidden(true); columns.Bound(o => o.Something2).Hidden(true); columns.Bound(o => o.Something3).Hidden(true); columns.Bound(o => o.MyObject.Something4).Hidden(true); }) %>This works great and all as I'm able to sort, group, and all the above.
My situation is I have many properties on MyObject and some edges cases are popping up that are yielding a couple megabytes of response data. The reason being there are many hidden columns that are situational dependent that a user can right-click/show. The problem is all these extra hidden columns are getting response data. And since the act of grouping and ungrouping fetches for data anyways, why does all the extra data have to come with it?
If I could have only the data returned that is necessary to populate the visible columns plus say a couple that I could mark somehow with a custom attribute, that would immensely help cut back on the size of the returned data.
So I took to converting my list of objects to a DataTable that I could then conditionally add columns + data for and then feed that to the GridModel. This worked well up until trying to group by a column that is in a nested object such as o.MyObject2.Color.
I run into this exception:
Property with specified name: MyObject2.Color cannot be found on type: System.Data.DataRowView
I guess this makes sense, but how do I overcome this? When I use Object Shredder, it sets each property of MyObject loosely typed such as ["Name"] which is a string and ["MyObject2"] which is MyObject2. But everything past ["MyObject2"] is strongly typed: (dataRow["MyObject2"] as MyObject2).Color. And this is where is gets over my head.
Is there another way to overcome my initial issue of all that extra data being sent that isn't used? Or, is there any advice with the DataTable bit? I've also tried converting the DataTable to a IEnumerable<Dynamic> with no such luck. The serialized Json is quite empty. I've also tried flattening all nested objects such as having datarow["MyObject2.Color"] as string, but this wreaks havok when referencing this column in JavaScript so I had to go with an underscore delimiter ["MyObject2_Color"] but this really screws up binding Columns in the UI. There has to be a way!