This is a migrated thread and some comments may be shown as answers.

Read-only grid bound to child collection in my view model

2 Answers 69 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 20 Jul 2015, 10:04 AM

Hi there,

I'm sure there's an easy way to do this but I can't seem to figure it out from the various examples I've seen using the Kendo Grid.  I have a view which has a model, and I want a grid to appear on the page populated from a collection that is a child property in my model.  The grid is 100% read-only for display only, and doesn't need any server side binding.  It also doesn't need paging, but client side sorting would be helpful.  Here is my model :-

public class RegisterViewModel
    {
        public int RegisterID { get; set; }
        public string BuildingDesignation { get; set; }
        public string BuildingDescription { get; set; }
        public string AgeOfBuilding { get; set; }
        public string ConstructionType { get; set; }
        public int? PhotoID { get; set; }
        public List<Sample> Samples { get; set; }
        public string EmployeeName { get; set; }
    }

The property I want to generate the grid from is Samples.  The other properties are just normal properties I put into a form on the page.

Any help of how to accomplish this would be appreciated.  As it stands, the only way I can think to achieve this is to loop through the collection and draw out a HTML table row by row, but I'd like if possible to keep it as a Kendo grid in line with other gris in my application.

Many thanks, Mark

2 Answers, 1 is accepted

Sort by
0
Accepted
Boyan Dimitrov
Telerik team
answered on 22 Jul 2015, 07:48 AM

Hello Mark,

I would suggest initially populate the grid from the model as shown in the Server Binding and enable Ajax in the data source. 

In addition you can disable the server operations in order to have client-side sorting. 

.DataSource(dataSource => dataSource
       .Ajax()
       .ServerOperations(false)
       .Model(model => model.Id(p => p.ID))
       ....
      .Read(read => read.Action("Read", "Home"))
)

 

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Mark
Top achievements
Rank 1
answered on 22 Jul 2015, 10:49 AM

Thanks Boyan,

I've managed to get the desired functionality now from this.

Mark

Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Mark
Top achievements
Rank 1
Share this question
or