John x
John x

Reputation: 4031

Assign column name as class name telerik grid mvc

i have a telerik grid in my view and i want to assign the column name as the class attribute

 .Columns(columns =>
        {

            columns.Bound(o => o.xyz).Width(70).Groupable(false).Title("Reply Status").HtmlAttributes(new { @class=xyz});      
                            ------^                                                                    -------------^                                         
        })

is that possible.

Upvotes: 0

Views: 1523

Answers (3)

Dakait
Dakait

Reputation: 2620

First of all make sure you are strongly binding the view with the model

Next you can try

.Columns(columns =>
      {    
        columns.Bound(o => o.xyz).Width(70).Groupable(false).Title("Reply Status")
                                        .HtmlAttributes(new { @class="<#=xyx#>"});                                    
        columns.Template(t => { }).ClientTemplate(                    
                "<span class='<#=xyx#>'>some randon text</span>"                    
                );
    })

Upvotes: 0

Petur Subev
Petur Subev

Reputation: 20213

Yes it is possible but the approach is different depending on your binding. I assume you are using Ajax binding, if this is the case then:

columns.Bound(o => o.xyz).Width(70).Groupable(false).Title("Reply Status").HtmlAttributes(new { @class="<#= xyz #>"});   

If you are using Server binding you should use the CellAction method. If you have difficulties with the latter let me know I will give you an example.

Upvotes: 1

Sanja Melnichuk
Sanja Melnichuk

Reputation: 3505

Telerik mvc grid columns should be bound to class properties only. You can also use dynamic model binding here the sample

Upvotes: 1

Related Questions