Templates
The ListView enables you to use templates for rendering its items.
The referred template displays the result that is set by the service.
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "https://demos.telerik.com/kendo-ui/service/Products",
dataType: "jsonp"
}
}
});
$("#listView").kendoListView({
dataSource: dataSource,
template: kendo.template($("#template").html())
});
The outermost HTML element in the template must be enclosed in another container such as a
div
orspan
element.
The following example demonstrates the full implementation of the suggested approach.
<div id="listView" style="max-height:400px;overflow:auto;"></div>
<script type="text/x-kendo-tmpl" id="template">
<div class="product">
<img src="https://demos.telerik.com/kendo-ui/content/web/foods/#= ProductID #.jpg" alt="Kendo UI for jQuery ListView #: ProductName # " />
<h3>#:ProductName#</h3>
<p>#:kendo.toString(UnitPrice, "c")#</p>
</div>
</script>
<script>
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "https://demos.telerik.com/kendo-ui/service/Products",
dataType: "jsonp"
}
}
});
$("#listView").kendoListView({
dataSource: dataSource,
pageable: true,
template: kendo.template($("#template").html())
});
</script>