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

Set columns to be editable dynamicaly (MVC)

3 Answers 280 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 05 Apr 2016, 08:15 PM

Is there any way to set a column to be editable or not simply based by name?

For example, I want to pass in via ViewData a list of column names and then make those columns uneditable. How could I go about doing this in such a way that I can add very little code to all of my Views and be able to to turn these columns to be editable/uneditable?

3 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 07 Apr 2016, 02:23 PM

Hello Alex,

First could you please clarify whether you are using the Kendo UI ASP.NET MVC wrappers? If so the editable option should be set in the Model configuration of the DataSource. Simply you can interate through the data stored in the ViewData and define the configuration for each field in the DataSource. 

I would suggest to use the Bind the Kendo UI MVC Grid to a DataTable project as a base project. 

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
Alex
Top achievements
Rank 1
answered on 07 Apr 2016, 09:09 PM

I am indeed using MVC with Razor.

I can figure out how to iterate through the ViewData just fine. My question, is how can I dynamicaly bind columns based on the values in ViewData.

 

I'm looking to do something like the following. But this obviously doesn't compile.

 

@(Html.Kendo().Grid<eRPortalDashboard.Models.TestViewModel>()
    .Name(uniqueName)
    .Columns(columns =>
    {       
        foreach (string col in ViewData["cols"])
        {
            columns.Bound(col);
        }
    })
 
.
.
.
.
.

 

0
Accepted
Boyan Dimitrov
Telerik team
answered on 11 Apr 2016, 12:08 PM

Hello Alex,

 

Please find attached a sample solution that implements the desired behavior. 

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Alex
Top achievements
Rank 1
Share this question
or