【问题标题】:Kendo Grid - PopUp Editing: Differentiate between 'Edit' and 'Add'Kendo Grid - 弹出编辑:区分“编辑”和“添加”
【发布时间】:2015-07-30 22:25:35
【问题描述】:

我有一个 Kendo 网格,它具有自定义编辑按钮和一个工具栏,可让您添加新的。

编辑/新建功能仅使用一个模板。

如何判断我是处于“编辑”模式还是“新建”模式。

我的代码(剑道网格):

 @(Html.Kendo().Grid(Model.OtherBreeds)
              .Name("grdOtherBreeds")
              .HtmlAttributes(new { @class = "grid" })
              .Columns(columns =>
              {
                  columns.Bound(c => c.OrganizationName);
                  columns.Bound(c => c.Prefix);
                  columns.Bound(c => c.Name);
                  columns.Bound(c => c.MemberId);
                  columns.Template(e => { })
                      .ClientTemplate(KendoTemplates.ActionColumn.WithEdit().WithDelete().Get())
                      .Visible(true)
                      .Title(Resources.Actions)
                      .Width(Constants.GridCommandColumnWidth);
              })
              .DataSource(dataSource => dataSource
                  .Ajax()
                  .PageSize(50) //? standard page size when grid is only UI element on screen?
                  .Model(model =>
                  {
                      model.Id(p => p.Id);
                      model.Field(p => p.OrganizationName);
                      model.Field(p => p.Prefix);
                      model.Field(p => p.Name);
                      model.Field(p => p.MemberId);
                  })
              )
              .Events(e => e.DataBound(KendoEventHandlers.DataBound.WithNoData(Resources.NoOtherBreedsForCustomer).Get()))
              .Sortable()
              .Pageable()
              .Filterable()
              .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("OtherBreedTemplate").Window(w => w.Width(500).Title("Add Other Breed")))
              .ToolBar(toolbar =>
              {
                  toolbar.Template(KendoTemplates.Toolbar.WithAdd("Add Other Breed").Get());
              })
              )  

【问题讨论】:

  • 在添加模式下您的 Id=0 / null 吗??
  • 是的,我试过用 JS 检查,但它似乎不起作用。我有一个函数可以在模板中获取 Id 的值,但它总是记录 null。
  • 有一个Edit 事件,您可以在显示弹出窗口之前捕获表单数据,应该有一个e.model.isNew() 可以检查
  • 添加和编辑的 ID 是否为空?它应该是一个实数,用于编辑和 null 或 0 或“”,具体取决于添加的数据类型。

标签: javascript c# asp.net-mvc kendo-ui kendo-grid


【解决方案1】:

您可以为 Edit 添加事件处理程序

.Events(e => e.Edit("onEdit"))

这应该为您提供模型和窗口所需的一切

<script>   
    function onEdit(e) {
        if (e.model.isNew()) {
            //the e.container is the PopUp window
            e.container.find(".class").text("New");
        }
    }
</script>

【讨论】:

  • 已经有一个事件附加到.Edit...我可以添加多个吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-07-29
  • 1970-01-01
  • 2017-11-27
  • 1970-01-01
  • 1970-01-01
  • 2015-10-27
  • 1970-01-01
相关资源
最近更新 更多