I'm trying to display 4 view model properties as columns in an igGrid control. I'm creating the grid in a Razor view using the chaining method. The grid columns are set up as follows:
@(Html.Infragistics().Grid<MediaViewModel>() .ID("grid").AutoGenerateColumns(false) .Columns(c => { c.For(media => media.Media.ID).DataType("number").HeaderText("ID"); c.For(media => media.Media.Description).DataType("string").HeaderText("Description"); c.For(media => media.Option1).DataType("string").HeaderText("Option 1"); c.For(media => media.Option2).DataType("string").HeaderText("Option 2"); }).ClientDataSourceType(ClientDataSourceType.JSON).DataSourceUrl(Url.Action("GetGridData")).DataBind().Render())
And the view model looks like this:
public class MediaViewModel {public EntityLayer.EntityObjects.Media Media { get; set; }
public string Option1 { get; set; }
public string Option2 { get; set; }
}
Note that the Media class referred to as a property in the MediaViewModel class, contains several public properties, two of which are ID (int) and Description (string).
So, the issue is that the ID and the Description cells in the grid are empty, but the Option1 and Option2 text is displayed fine. I realise I could get it working if I flattened the MediaViewModel class so that the ID and Description properties belong immediately to the MediaViewModel class, but I'd like to keep the current structure.
Please help me with this as I can't find this issue listed anywhere. The lambda expressions for the columns ID and Description refer to the properties I want to display, so I'm not sure what's going on.
Kind regards,
Stephen
Hello Stephen,
Thank you for posting in our forums.
Currently igGrid doesn't support binding to comples properties.
You can use the suggested approach below by creating new wrapper classes, and filling them based on the collections you already have in place:
http://ko.infragistics.com/community/forums/p/67863/344886.aspx#344886
Another workaround is using templating. In the html Tooltip sample is demonstrated this with the rowTemplate for showing the images in the grid:
http://ko.infragistics.com/products/jquery/sample/grid/tooltip-popover
Hope this helps.
Thanks for your reply, but the Media object is definitely initialised. I've checked in the VS debugger and I have verify that the Media object for all items in the collection of MediaViewModel has been populated. I have also verified using the Chrome browser developer tools that the data source is populated correctly for the Infragistics igGrid. The problem appears to be with displaying the Media values, not due to the population.
Cheers,
2 suggestions
Hope this helps,
Regrads