I've seen examples in doing this in kendo ui
https://docs.telerik.com/kendo-ui/knowledge-base/use-nested-model-properties
but i can't figure out how in mvc. I have two nested fields that i need to force the grid to treat as dates.
1 Answer, 1 is accepted
Hello John,
Thank you for the details provided.
In MVC the nested properties are properties to another Model. As the Telerik UI Grid needs a flat structure of data, the nested properties could be shown with the help of a ClientTemplate, but they will always be string typed.
In order to achieve the desired behavior, I would recommend making the pointed Date fields - part of the Main Model and using them as flat data out of the box.
If the Date columns do not need to have behavior as Dates and only to be represented - let me know if assistance is needed for achieving this result.
Kind Regards,
Anton Mironov
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.
So you're saying the mvc wrapper doesn't support this? I did in fact move copies of the fields into the base model using notmapped fields, since the datasource is a List<model> so it didn't break filters. However it looks like this feature is supported on the jquery grids..
I know my way around your grids pretty well. I was just hoping there would be an easier way than flattening the model. This particular grid has a hundred columns in it so it would be a tedious job.
Hello John,
The approach is actually applicable in the ASP.NET MVC scenario when using the wrappers, but since the wrappers are strongly typed Grid<T>, you cannot bind the field to a column. What you can do is use a dynamic type for the declaration of the Grid, which is not the best practice, but it should do the trick.
Thus, when you declare the field in the schema, it could be bound to a column. Please review the following snippet for more details:
@(Html.Kendo().Grid<dynamic>()
.Name("grid")
.Columns(columns =>
{
columns.Bound("OrderID").Filterable(false);
columns.Bound("TestDate").Title("Test Date");
})
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.HtmlAttributes(new { style = "height:850px;" })
.DataSource(dataSource => dataSource
.Custom()
.PageSize(65)
.Transport(t => t.Read("Orders_Read", "Grid"))
.Schema(schema => schema.Data("Data").Model(m => m.Field("TestDate", typeof(DateTime)).From("Test.TestDate")))
)
)
To flatten your data, you can create a new DTO and use it instead of using the current object for the Grid.
For example, if you have the following structure:
public class Person
{
public string Name { get; set; }
public Child Child { get; set; }
}
public class Child
{
public string Name { get; set; }
}
You can create a Person DTO :
public class PersonDTO
{
public string Name { get; set; }
public string ChildName { get; set; }
}
and map the person to a PersonDTO, and use it in the Grid. For more information, you can review the following article:
https://docs.microsoft.com/en-us/aspnet/web-api/overview/data/using-web-api-with-entity-framework/part-5
Hello John,
Thank you for your feedback and for sharing your decision on how to proceed from here.
Surely the discussion would be useful to other people from the community who are working on a similar to your scenario.
Hi John,
Thank you for pointing this one to our attention. I am now increasing your points with a count of 500.
If further information or assistance is needed, do not hesitate to contact the team.
Kind Regards,
Anton Mironov