KendoGrid column as dropdown

4 posts, 0 answers
  1. Anamika
    Anamika avatar
    124 posts
    Member since:
    Mar 2014

    Posted 08 Feb Link to this post

    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

  2. Dimo
    Admin
    Dimo avatar
    8333 posts

    Posted 10 Feb Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Anamika
    Anamika avatar
    124 posts
    Member since:
    Mar 2014

    Posted 11 Feb in reply to Dimo Link to this post

    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

     

  5. Dimo
    Admin
    Dimo avatar
    8333 posts

    Posted 15 Feb Link to this post

    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
Back to Top
UI for ASP.NET MVC is VS 2017 Ready