I have kendo grid having some columns. I'm trying to hide a checkbox conditionally using client template. When i using client Template it works fine. The above code hide the element when the condition true.
@(Html.Kendo().Grid<Spectrum.Model.CustomerInterestItem>()
.Name("customerInterestInfoGrid")
.AutoBind(true)
.Columns(columns =>
{
columns.Bound(c => c.ID).Width(200);
columns.Bound(c => c.SubscriptionEndDate).Title("End Date").Format("{0:MMM dd, yyyy}").Width(130);
columns.Bound(c => c.Notes).Width(200);
columns.Template(@<text></text>)
.ClientTemplate("#if (!InterestTypeID == 99) {#"
+"<input name='chkSubscribed' class='subscribedClass' type='checkbox' data-bind='checked: IsSubscribed' #= IsSubscribed ? checked='checked' : '' #/>"
+ "#} #").Width(130).Title("Subscribed");
columns.Command(command => { command.Edit(); command.Destroy(); });
})
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => { model.Id(c => c.ID); model.Field(f => f.Notes).Editable(false); model.Field(f => f.IsSubscribed).Editable(false); })
.Read(cfg => cfg.Action("testGridRead", "Customer").Data("customerIDData"))
.Update(cfg => cfg.Action("EditInterestItem", "Customer"))
.Destroy(cfg => cfg.Action("DeleteInterestItem", "Customer"))
.ServerOperation(false)
)
.Pageable(pageable => pageable
.Enabled(true)
.PageSizes(new int[3] { 10, 25, 50 })
.Refresh(true))
.Scrollable()
.Selectable()
.Sortable()
)
The above code will hide the check box. But my problem is , when i click update button then the checkbox become visible. I don't know the reason.
Try the below . You can give the condition inside the client template itself
columns.Bound(c => c).Width(50).Title("Subscribed").ClientTemplate("<input type='checkbox' name='chkSubscribed' class='subscribedClass' #=InterestTypeID =='99' ? \"checked='checked' \" : '' # />");