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

How to add columns dynamically to the kendo grid

4 Answers 606 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Prasanth
Top achievements
Rank 1
Prasanth asked on 22 Apr 2016, 07:05 AM

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.

4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 26 Apr 2016, 12:06 PM
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
0
Prasanth
Top achievements
Rank 1
answered on 02 Aug 2016, 05:37 PM

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.

0
Prasanth
Top achievements
Rank 1
answered on 02 Aug 2016, 05:39 PM
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. 
0
Tsvetina
Telerik team
answered on 05 Aug 2016, 10:42 AM
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
Tags
General Discussions
Asked by
Prasanth
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Prasanth
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or