user1987292
user1987292

Reputation: 41

Use mvc display template in kendo grid

I've got Kendo grid:

@(Html.Kendo().Grid<SomeType>()
.Columns(columns =>
{
    (...)
    columns.Bound(customer => customer.IsActive);
}

and I've got an mvc display template (Views/Shared/DisplayTemplate/bool.cshtml)

@model bool
@Html.CheckBoxFor(model => model, new { disabled = "true" })

(I tried also with Boolean as a type and template file name)

This works perfectly outside a grid but in grid true/false is shown (that comes from default mvc display template I suppose).

How make kendo grid to use appropriate display template?

(Settings UIHint doesn't help)

Upvotes: 4

Views: 7090

Answers (2)

Eric
Eric

Reputation: 17536

I sort of found a way, but it is far from ideal because the ViewModel must only have string members for this to work....and we're really just using a partial view...

DisplayTemplate.cshtml:

@model ViewModel
@Html.Partial("PartialView", Model)

PartialView.cshtml:

@model ViewModel
@* write schtml here *@

KendoGuid.cshtml

...
.Columns(columns =>
{
    columns.Bound(x => x.GridViewModelField)
        .ClientTemplate("PartialView", new ViewModel
        {
            ViewModelField = "#=GridViewModelField#",
        }).ToHtmlString());
})
...

Upvotes: 0

Pablo Claus
Pablo Claus

Reputation: 5920

Try something like this:

columns.Bound(p => p.GrasaDielectrica).ClientTemplate("<input type='checkbox' #= GrasaDielectrica ? checked='checked' : '' # disabled='disabled' ></input>")

Upvotes: 2

Related Questions