ListView

Description

The ListView widget allows for a custom layout of a collection

Official Kendo UI ListView documentation

Examples

  • Basic Example
  • Passing additional options
  • Using Knockout templates
  • Using global options

This example demonstrates passing the basic options required by the ListView plugin.

<div data-bind="kendoListView: { data: items, template: template }"> </div>
var ViewModel = function() {
    this.items = ko.observableArray([
        { id: "1", name: "apple"},
        { id: "2", name: "orange"},
        { id: "3", name: "banana"}
    ]);
    this.template = kendo.template('<div>#= name #</div>');
};

                            ko.applyBindings(new ViewModel());

This example demonstrates passing additional options in the data-bind attribute. The Add Item button updates the underlying data and shows that the ListView remains in sync.

<div data-bind="kendoListView: { data: items, navigatable: true, selectable: true, template: template }"> </div>
<button data-bind="click: addItem">Add Item</button>
var ViewModel = function() {
    this.items = ko.observableArray([
        { id: "1", name: "apple"},
        { id: "2", name: "orange"},
        { id: "3", name: "banana"}
    ]);
    this.template = kendo.template('<div>#= name #</div>');
    
    this.addItem = function() {
        var num = this.items().length + 1;
        this.items.push({ id: num, name: "new" + num});
    };
};

                            ko.applyBindings(new ViewModel());

This example demonstrates using a Knockout template for the list view row.

<div data-bind="kendoListView: { data: items, template: 'listTmpl', useKOTemplates: true }"> </div>

<button data-bind="click: addItem">Add Item</button>

<script id="listTmpl" type="text/html">
    <div>
        <span data-bind="text: id"></span>
        <input data-bind="value: name" />
        <a href="#" data-bind="click: $root.removeItem"> x </a>
    </div>
</script>
var ViewModel = function() {
    this.items = ko.observableArray([
        { id: "1", name: ko.observable("apple")},
        { id: "2", name: ko.observable("orange")},
        { id: "3", name: ko.observable("banana")}
    ]);

    this.addItem = function() {
        var num = this.items().length + 1;
        this.items.push({ id: num, name: ko.observable("new" + num)});
    };

    this.removeItem = function(item) {
        this.items.remove(item);
    }.bind(this);
};

                            ko.applyBindings(new ViewModel());

This example demonstrates setting global options in ko.bindingHandlers.kendoListView.options. This helps to simplify the markup for settings that can be used as a default for all instances of this widget.

<div data-bind="kendoListView: { data: items, template: template }"> </div>
<button data-bind="click: addItem">Add Item</button>
var ViewModel = function() {
    this.items = ko.observableArray([
        { id: "1", name: "apple"},
        { id: "2", name: "orange"},
        { id: "3", name: "banana"}
    ]);
    
    this.template = kendo.template('<div>#= name #</div>');
    
    this.addItem = function() {
        var num = this.items().length + 1;
        this.items.push({ id: num, name: "new" + num});
    };
};

ko.bindingHandlers.kendoListView.options = {
    navigatable: true,
    selectable: true
};

                            ko.applyBindings(new ViewModel());

Live Options

The kendoListView.md binding accepts all of the options that can be specified for the widget. However, when bound against an observable, these live options will update the widget or respond to updates from interactions with the widget.
data

An array, observableArray, or kendo.data.DataSource to be rendered in the list

widget

If specified, will populate an observable with a reference to the actual widget