开发者

Telerik MVC: Generic Grid

开发者 https://www.devze.com 2023-01-09 20:46 出处:网络
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.

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 Teleri开发者_如何学JAVAk MVC Grid only knows how to make a column, if you explicitly refer a model property.


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);           
            }
        })
0

精彩评论

暂无评论...
验证码 换一张
取 消