Greetings,I have a model class similar to this:
public class Object1{ public string Id {get ;set; } public string Name {get ;set; } public Object2 SubObject1 {get ;set; } public Object3 SubObject2 {get ;set; }}}
Then I'm using the grid as follows:
@(Html.Infragistics() .Grid(Model) .ID("grid") .Width("100%") .Height("500px") .PrimaryKey("Id") .AutoGenerateColumns(false) .AutoGenerateLayouts(false) .Columns(column => { column.For(x => x.Id).HeaderText("Id").Width("20%"); column.For(x => x.Name).HeaderText("Name").Width("20%"); column.For(x => x.SubObject1.Name).HeaderText("SubObject First Name").Width("30%"); column.For(x => x.SubObject2.Name).HeaderText("SubObject Second Name").Width("30%"); }) .DataBind() .Render() )
Id and Name on the root object do bring their values, but I've tried many variations and I have not been able to get the values for the Navigation Properies to work; Any ideas would be greatly appreciated.
Thanks
Hi there,
Our MVC helpers serialize the entire MVC models and thus the grid cannot recognize what sub-property of the serialized object it should render. However you can define a template and provide to the grid what property the column should use as the value. Here's an example:
column.For(x => x.SubObject1.Name).HeaderText("SubObject First Name").Template("${SubObject1.Name}").Width("30%");
column.For(x => x.SubObject2.Name).HeaderText("SubObject Second Name").Template("${SubObject2.Name}").Width("30%");
Keep in mind that features are limited on such objects, due to the same reason. For example, if you want to sort the values in that column, the grid would have to perform sorting on an object collection, and it wouldn't be able to infer which property, or which set of properties it should sort on. In order to have that work as you expect you would have to define a custom sorting function to the sorting settings for the particular column and provide what properties of the data the grid should sort by.
Thank you for using the Infragistics forum!