How to add columns dynamically to the kendo grid

5 posts, 0 answers
  1. Prasanth
    Prasanth avatar
    5 posts
    Member since:
    Jan 2016

    Posted 22 Apr Link to this post

    Hi Experts,

    I have a scenario to add the columns dynamically to the kendo grid. I will get the columns from the stored procedure based on the criteria selection from the UI and I need to display those columns in the kendo grid. I have the case like one criteria will give 20 columns and another criteria will give 40 columns etc. So how can i handle view model and how to display them in kendo grid.

    Please respond as soon as possible.

    Thanks you in anticipation.

  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 26 Apr Link to this post

    Hi,

    You can check the Kendo UI Grid demos and also this and this forums. 

    I would encourage you to refer to the respective forum category for Kendo UI Grid widget on specific questions where my colleagues with deeper knowledge in the specific product can address the case. 

    Regards,
    Dimitrina
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Prasanth
    Prasanth avatar
    5 posts
    Member since:
    Jan 2016

    Posted 02 Aug in reply to Dimitrina Link to this post

    Hi Dimitrina,

    i am binding the columns dynamically like below

     for (int col = 0; col < Model.Count; col++)
            {
                if (Model[col].isIskuAttr > 0)
                {
                    columns.Bound("field" + col).Title(Model[col].attribute).Filterable(ftb => ftb.Multi(true)).Width(200).HtmlAttributes(new { @style = "font-size:8pt;font-family:Arial,sans-serif;text-align:center;" }).HeaderHtmlAttributes(new { @class="iskuAttr",@style="background-color:blue"}).Width(100);
                }
                else
                {
                    columns.Bound("field" + col).Title(Model[col].attribute).Filterable(ftb => ftb.Multi(true)).Width(200).HtmlAttributes(new { @style = "font-size:8pt;font-family:Arial,sans-serif;text-align:center;" }).HeaderHtmlAttributes(new { @class = "blueConfigAttr", @style = "background-color:darkblue" }).Width(250);
                }
            }

     

     

    in the above code, i am applying EditorTemplateName("AvailableValues"), this template will be applied to all columns. when my row went to edit mode. only one row is able to load the editor template. i want all rows to load the same editor template.

     

    here is the code of my editor template

     

    @{
        Layout = null;
    }

    @using Kendo.Mvc.UI


    @(Html.Kendo().DropDownList()
              .Name("products")
              .DataTextField("Text")
              .DataValueField("Value")
              .DataSource(source =>
              {
                  source.Read(read =>
                  {
                      read.Action("getAttributeValues", "BrowseProducts");
                  });
              })
              .HtmlAttributes(new { style = "width: 100%" })
    )

     

     

    Can we use same template for all columns in the or we need to use different for every column ? please help me on this.

  4. Prasanth
    Prasanth avatar
    5 posts
    Member since:
    Jan 2016

    Posted 02 Aug in reply to Dimitrina Link to this post

    Can we apply same editor template for all the columns, my editor template load dropdowns for all cell in the row? editor template contains code for loading the dropdown. only for one cell template is loading. 
  5. Tsvetina
    Admin
    Tsvetina avatar
    1876 posts

    Posted 05 Aug Link to this post

    Hello Prasanth,

    This forum is for discussions about Telerik Platform by Progress, which is an end-to-end solution for developing and distributing mobile apps. You seem to be working on an ASP.NET MVC project, so please post your question in the respective forum or in Stack Overflow where community discussions about Kendo UI take place.

    Regards,
    Tsvetina
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top