Set columns to be editable dynamicaly (MVC)

4 posts, 1 answers
  1. Alex
    Alex avatar
    76 posts
    Member since:
    May 2015

    Posted 05 Apr 2016 Link to this post

    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?

  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2062 posts

    Posted 07 Apr 2016 Link to this post

    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!
     
  3. Alex
    Alex avatar
    76 posts
    Member since:
    May 2015

    Posted 07 Apr 2016 in reply to Boyan Dimitrov Link to this post

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

     

  4. Answer
    Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2062 posts

    Posted 11 Apr 2016 Link to this post

    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!
     
Back to Top