Frank Michael Kraft
Frank Michael Kraft

Reputation: 2362

Telerik MVC: Generic Grid

I am wondering if I could design a generic way to design a Telerik MVC Grid. Example: Model is a List of FieldDescriptor. A FieldDescriptor has a name, a value and a type. Thus I want to show the colums of the Grid according to the data in the model - depending on which fields come and what their type is. But the Telerik MVC Grid only knows how to make a column, if you explicitly refer a model property.

Upvotes: 2

Views: 1173

Answers (1)

Tony Borf
Tony Borf

Reputation: 4660

I found a blog that explained what I think you are asking. How to display a dynamic datatable when you don't know what the columns are until run time.

You can loop through the columns in model to build the grid, then use ajax to go get the data.

Here the link www.alexrogan.com

Here is how you can loop through the column values of a datatable to create the grid columns.

        .Columns(columns => 
        {
            foreach (System.Data.DataColumn column in Model.Columns)
            {
                columns.Bound(column.DataType, column.ColumnName);           
            }
        })

Upvotes: 7

Related Questions