3

我正在尝试借助本文档将下拉列表添加到剑道网格:http: //demos.telerik.com/aspnet-mvc/grid/editing-custom

实际上我遵循了完全相同的方式,但没有机会我想知道剑道网格如何理解它必须在 clientTemplate 中放置一个下拉列表?!clientTemplate 是否必须在某处定义?

4

2 回答 2

1

您必须通过将其添加到 Grid 来定义 clientTemplate.ClientDetailTemplateId("template")
然后您可以将 DropDownList 添加到模板中

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

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

于 2015-01-30T02:11:07.520 回答
0

只是为了增加答案,这是一个迟到的答案......

  • 在您的 ViewModel 中创建一个列表
  • 将您的 Model.PropertyId 视为 ForeignKey

例如...

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

样品视图:

@(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;" }))

样品视图模型:

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
}
于 2018-08-21T16:52:11.977 回答