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

KendoGrid column as dropdown

3 Answers 589 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anamika
Top achievements
Rank 1
Anamika asked on 08 Feb 2016, 08:41 AM

Hello,

 

I have been through all samples but non match the Scenario i have. My Kendo grid is inside a vertical splitter and the columns are dynamic. So in datagrid read Event the Controller picks a variable select stetement and then the columns and column Header names are stored in viewbag and in view the columns get bound to viewbag and datab\able returned from controlller method. One column should be editable as Dropdown and rest all not editable.

 

Attached is my view code  and this is the column i am trying to use adropdown  editortemplate and when i add this editable line i get crash

.Editable(editable => editable.Mode(GridEditMode.InCell))

Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.

 if (ViewBag.ObjAdressHeader[k, 0] == "Obj_AddressType"){
                        columns.Bound(ViewBag.ObjAdressHeader[k, 0]).Title(ViewBag.ObjAdressHeader[k, 1]).EditorTemplateName("AvailableValues").Width(70);
                       // columns.ForeignKey("Obj_AddressType", (System.Collections.IEnumerable)ViewBag.AddressTypes, "Value", "Text").EditorTemplateName("AvailableValues").Title("Typ").Width(70);
                      
                    }

 

My editortemplatelooks like

 @(Html.Kendo().DropDownList().Name("Obj_AddressType")
            .DataTextField("Text")
                 .DataValueField("Value")
       .BindTo(new List<SelectListItem>
                   {
                        new SelectListItem {Text = "Kunde", Value = "0"},
                       new SelectListItem {Text = "Kunde", Value = "1"},
                       new SelectListItem {Text = "Rechnungsadresse", Value = "2"}
                   }))

 and view code

  rightverticalPanes.Add()
             .HtmlAttributes(new { id = "bottom-pane" })
             .Resizable(true)
             .Collapsible(false)
             .Content(@<text>
                        @(Html.Kendo().Grid(Model)
    .Name("Grid_ObjAdress")
     .DataSource(dataSource1 => dataSource1
                    .Ajax()
                    .PageSize(100)
                    .Model(model1 =>
                    {
                        if (Model != null)
                        {
                            foreach (System.Data.DataColumn ocolumn in Model.Columns)
                            {
                                if( ocolumn.ColumnName == "Obj_AddressType"){
                                    model1.Field(ocolumn.ColumnName, ocolumn.DataType).Editable(true);
                                }else{
                                model1.Field(ocolumn.ColumnName, ocolumn.DataType).Editable(false);
                                }
                            }
                        }
                    })
                    .Read(read => read.Action("ObjectAdress_Read", "ObjektActivity"))
 .ServerOperation(false)
                     )
                      .Resizable(resize => resize.Columns(true))
    .Columns(columns =>
    {
        if (ViewBag.ObjAdressHeader != null)
        {
            for (int k = 0; k < ViewBag.ObjAdressHeader.GetLength(0); k++)
            {
                if (ViewBag.AdrVisibleCols[k] == "0")
                {
                    columns.Bound(ViewBag.ObjAdressHeader[k, 0]).Title(ViewBag.ObjAdressHeader[k, 1]).Visible(false);
                }
                else
                {
                    if (ViewBag.ObjAdressHeader[k, 0] == "Obj_AddressType"){
                        columns.Bound(ViewBag.ObjAdressHeader[k, 0]).Title(ViewBag.ObjAdressHeader[k, 1]).EditorTemplateName("AvailableValues").Width(70);
                       // columns.ForeignKey("Obj_AddressType", (System.Collections.IEnumerable)ViewBag.AddressTypes, "Value", "Text").EditorTemplateName("AvailableValues").Title("Typ").Width(70);
                      
                    }
                    else
                    {
                        columns.Bound(ViewBag.ObjAdressHeader[k, 0]).Title(ViewBag.ObjAdressHeader[k, 1]).Width(120);
                    }
                }
            }
        }
    })
         .Editable(editable => editable.Mode(GridEditMode.InCell))
            .Selectable(selectable => selectable
                    .Mode(GridSelectionMode.Multiple))
                     .Sortable()
                     .Scrollable()
        .Filterable(filterable => filterable
                                          .Extra(false)
                                          .Operators(operators => operators
                                              .ForString(str => str.Clear()
                                                  .StartsWith("Starts with")
                                                  .IsEqualTo("Is equal to")
                                                  .IsNotEqualTo("Is not equal to")
                                              ))
                                          )
                                      .Groupable()
                                      .Reorderable(r => r.Columns(true))
                            .Resizable(r => r.Columns(true))
                                      )

Thanks

 

Anamika

3 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 10 Feb 2016, 10:03 AM
Hi Anamika,

The following forum thread of yours seems to discuss the same issue.

http://www.telerik.com/forums/inline-batch-crud-fails-with-datatable-model

You may also want to look at:

http://www.telerik.com/forums/inline-editing-mode-and-dynamic-object
 
http://www.telerik.com/forums/problem-with-crud-operation-with-data-table-as-model

Regards,
Dimo
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
Anamika
Top achievements
Rank 1
answered on 11 Feb 2016, 07:30 AM

Hello Dino,

 

Thanks for the post but i just got it working myself. But still not sure why the kendogrid behaves this way. As you can see in model i have if case if column is obj_addresstype then cell is editable or else not. And i had to add Editortemplate as normal Texteditor for all other field except for the obj_addresstype which is Dropdown.

columns.Bound(ViewBag.ObjAdressHeader[k, 0]).Title(ViewBag.ObjAdressHeader[k, 1]).EditorTemplateName("TextBoxEditor").Width(120); 

Now when i run everything is fine and i can see Dropdown as well. But rest all cells are also editable even if i set editable(false)

 I did Workaround to stop the cell editing in jquery. But not sure why this behaviour.

 Thanks

 

Anamika

 

0
Dimo
Telerik team
answered on 15 Feb 2016, 08:19 AM
Hi Anamika,

When popup edit template is used, field editability depends on what fields you have included in the template - the Model editability settings in the Grid DataSource declaration no longer matter, because the Grid is not generating the edit form.

Regards,
Dimo
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
Tags
Grid
Asked by
Anamika
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Anamika
Top achievements
Rank 1
Share this question
or