user584018
user584018

Reputation: 11304

telerik grid bnding with dynamic columns

I'm using telerik MVC grid and my columns are dynamic for grid, means I can't bind the grid with strongly type model.

Through Ajax call, somehow I get the data in below image format (there are 3 column)

now question, how can i bind these records to grid, currently below code display nothing.

 @model IEnumerable<dynamic>
 @(Html.Telerik().Grid(Model)
                .Name("grdHierarchy")
                .Sortable()
                .Pageable()
                .Scrollable(scrolling => scrolling.Enabled(true)))

Upvotes: 3

Views: 3413

Answers (4)

stricq
stricq

Reputation: 856

For a truly dynamic experience, i.e. you have no idea what the class will be and no idea what the properties will be until run time, you can combine these two concepts.

How to dynamically create a class in C#?

with

http://demos.telerik.com/aspnet-mvc/razor/Grid/ColumnSettings

Upvotes: 0

Ludwo
Ludwo

Reputation: 6173

Try it this way:

.Columns(columns => columns.LoadSettings(Model.Columns))

Where Model.Columns are defined this way:

public List<GridColumnSettings> Columns { get; set; }

See this demo: http://demos.telerik.com/aspnet-mvc/grid/columnsettings

Upvotes: 1

syntax
syntax

Reputation: 91

I know this is old, but try this:

 .Columns(col => {                           
                   col.Bound("DynamicColumnName");
                 })

Just pass the column name as strings.

Upvotes: 0

Dick Lampard
Dick Lampard

Reputation: 2266

How about using the auto-generated columns concept presented here? Might be plausible for scenario like yours.

Upvotes: 1

Related Questions