1

我有一个网格,其中一列具有带下拉列表的EditorTemplate。基于列值在kendo ui网格中的列上启用或禁用EditorTemplateName

columns.Bound(i => i.TypeId).Title("Types").EditorTemplateName("Types").ClientTemplate("#: TypeId != 3 ? Type : '-'#").HtmlAttributes(new { @style = "text-align:center; " }).Width(75); 

模板

@(Html.Kendo().DropDownListFor(i => i) 
       .Name("TypeId") 
       .DataValueField("Id") 
       .DataTextField("Type") 
       .BindTo((IEnumerable)ViewBag.Types) 
       .OptionLabel("Select Type") 
       .Value("TypeId") 
) 

我要做到这一点是当typeid的是3,我不想编辑模板使用什么。我只想显示带有禁用状态的“ - ”。

我可以使用onedit事件禁用下拉菜单,但我不希望下拉菜单甚至在禁用状态下显示。

任何想法将不胜感激。

我所做的禁用模板如下:

function disableOnEdit(e) { 

     if (e.model.isNew()) { 
      // Leave it editable if the row is new. 
     } else { 
      //Disable the editor for Element in this row. 
      var select = e.container.find('input[name=TypeId]').data('kendoDropDownList'); 
      if (select != null && select._selectedValue == "3") { 
       //var text = select.find(".k - input"); 
       //select.dataSource = null; 
       //select._selectedValue = "-"; 
       //select.editTemplate = null; 
       //select.innerHTML = "-"; 
       //select._current[0].innerText = "-"; 
       select.enable(false); 
      } 
     } 
    } 

我已经尝试了很多东西,从列删除下拉列表。我是Kendo UI的新手,请帮助我。

感谢

+0

我已成功地暂时如下周围做一些工作。通过这种方式,我们编辑时不会显示下拉列表。 $('#TypeId')。parent()[0] .innerText =“ - ”; select.enable(false); – 2014-09-11 23:45:13

回答

0

你可以改变你的模板类似下面

@model Int32 

@if(Model !=3){ 
@(Html.Kendo().DropDownListFor(i => i) 
      .Name("TypeId") 
      .DataValueField("Id") 
      .DataTextField("Type") 
      .BindTo((IEnumerable)ViewBag.Types) 
      .OptionLabel("Select Type") 
      .Value("TypeId")) 
}else{ 
    @Html.TextBox("",Model,new{disabled="disabled"}) 
} 
+0

我喜欢这个概念。但由于它是编辑器模板,所以Model = 0的值始终是。我需要这个逻辑只有在他们试图编辑时才会被解雇。 – 2014-09-15 01:17:22

相关问题