3

I'm trying to add a dropdownlist to a kendo grid by the help of this documentation : http://demos.telerik.com/aspnet-mvc/grid/editing-custom

Actually I followed exactly the same way but no chance I'm wonder how the kendo grid understand it has to place a dropdownlist in the clientTemplate ?! does clientTemplate has to be defined somewhere?

tereško
  • 58,060
  • 25
  • 98
  • 150
user4092086
  • 986
  • 3
  • 12
  • 24

2 Answers2

1

You have to define a clientTemplate by adding this to the Grid .ClientDetailTemplateId("template")
Then you can add DropDownList into the template

<script id="template" type="text/kendo-tmpl">
    @(Html.Kendo().DropDownList()
       //build the dropdownlist
       .ToClientTemplate()
    )
</script>

Demo: http://demos.telerik.com/aspnet-mvc/grid/detailtemplate

Hien Tran
  • 1,443
  • 2
  • 12
  • 19
  • I want to put the dropdownlist inside a column of my table let's say column 3 then in this case how suggested solution knows where to put the dropdownlist? – user4092086 Jan 30 '15 at 14:06
0

Just to add to the mix of answers, here is a late one...

  • Create a List in your ViewModel
  • Treat your Model.PropertyId as a ForeignKey

For example...

columns.ForeignKey(x => x.ChangeTypeId, Model.ChangeTypes, "Id", "ChangeTypeName")

SAMPLE VIEW:

@(Html.Kendo().Grid<ChangeRequest>()
              .Columns(columns =>
              {
                  columns.Bound(x => x.Id)
                      .Visible(false);
                  columns.Bound(x => x.Description)
                      .Title("Description")
                      .Width(100);
                  columns.ForeignKey(x => x.ChangeTypeId, Model.ChangeTypes, "Id", "ChangeTypeName")
                      .Title("Data Type")
                      .Width(50);
                  columns.Command(command => { command.Edit(); command.Destroy(); }).Width(100);
              })
              .Name("gridChangeRequest")
              .ToolBar(toolbar => toolbar.Create())
              .Editable(editable => editable.Mode(GridEditMode.InLine))
              .Pageable()
              .Sortable()
              .Scrollable()
              .BindTo(Model.RTUDeviceCustomRegisterModbuses)
              .DataSource(dataSource => dataSource.Ajax()
                                                  .ServerOperation(true)
                                                  .PageSize(50)
                                                  .Model(model => { model.Id(m => m.Id); })
                                                  .Create(update => update.Action("Create", "ChangeRequest", new { Area = "Documents" }))
                                                  .Update(update => update.Action("Update", "ChangeRequest", new { Area = "Documents" }))
                                                  .Destroy(update => update.Action("Destroy", "ChangeRequest", new { Area = "Documents" }))
                                                  )
              .HtmlAttributes(new { @class = "", @style = "height: 400px;" }))

SAMPLE VIEW MODEL:

public class ChangeRequestFormViewModel : ViewModelBase
{
    #region <Constructors>

    public ChangeRequestFormViewModel(IApplication application) : base(application)
    {
        InitializeCreateEmpty();
    }

    #endregion

    #region <Properties>

    public ChangeRequestDocument Entity { get; set; }

    #region lookups

    public List<ChangeType> ChangeTypes { get; set; }

    #endregion

    #endregion

    #region <Methods>

    private void InitializeCreateEmpty()
    {
        var builder = Application.ChangeRequestDocumentXmlDataSetBuilder; //<-- This object is specific to my (particular) application
        var dataset = builder.CreateEmpty();

        Entity = dataset.Form;

        ChangeTypes = dataset.ChangeTypes;
    }

    #endregion
}
Prisoner ZERO
  • 13,848
  • 21
  • 92
  • 137