Enable or Disable EditorTemplateName on a column in a kendo ui grid based on the column value

2.4k Views Asked by At

I have a grid with one of the columns has an EditorTemplate with a dropdownlist.

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

template

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

what I want to achieve this is when the TypeId is 3 I don't want the editor templates to use. I just want to show the "-" with disabled state.

I could do the disabling of the dropdown with the onedit event but I don't want the dropdown to show even in a disabled state.

any Idea will be appreciated.

What I did to disable the templates as in below:

 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);
            } 
        }
    }

I have tried many things to remove the dropdownlist from the column. I am new to Kendo UI so please help me.

Thanks

1

There are 1 best solutions below

1
user3787534 On

You can change your template like below

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