Templates
The PropertyGrid allows you to control the appearance of the items values by using template options.
For more information on the capabilities and syntax of the templates, see the Using Client Templates article. For a runnable example, refer to the demo on customizing the templates in the PropertyGrid.
The following example demonstrates how to use the TemplateHandler()
option to customize the value of an item that has child items.
@(Html.Kendo().PropertyGrid<PropertyViewModel>()
.Name("propertyGrid")
.Items(items =>
{
items.Add().Field("font").TemplateHandler("fontTemplate")
.Items(childItems =>
{
childItems.Add().Field("fontWeight");
childItems.Add().Field("fontFamily");
});
})
... //Additional configuration
)
<script>
function fontTemplate(data) {
var propertyGridModel = $("#propertyGrid").data('kendoPropertyGrid').model();
return `<span class="fontWeight">${propertyGridModel.font["fontWeight"]}</span> <span class="fontFamily">${propertyGridModel.font["fontFamily"]}</span>`;
}
</script>
The following example demonstrates how to create an inline string template by using the Template()
option.
@(Html.Kendo().PropertyGrid<PropertyViewModel>()
.Name("propertyGrid")
.Items(items =>
{
items.Add().Field(f => f.color).Template("<i><span style='color:#=value#'>#=value#</span></i>")
.Editor(editor => editor
.DropDownList()
.BindTo(new string[] { "red", "green", "blue", "purple", "orange" }));
})
... //Additional configuration
)