Ext.view.View and Data

It's SUPER IMPORTANT to associate data with the store. If you specify data here it is provided to the tpl, but not properly bound to the store. Unless the store knows about the data itemclick events won't work.

by Walter Rumsby

HTML

<div id="container"></div>

CSS

body {
    font-family: sans-serif;
}
.x-dataview-item {
    margin: 4px;
    padding: 4px 8px;
    background-color: #ededed;
    line-height: 24px;
}
.x-item-selected {
    text-decoration: line-through;
}
.bold {
    font-weight: bold;
}

JavaScript

Ext.widget({
    xtype: 'dataview',
    renderTo: 'container',
    itemTpl: '<div>{name:htmlEncode}</div>',
    itemSelector: '.x-dataview-item',
    store: {
        fields: ['id', 'name'],
        // It's SUPER IMPORTANT to associate data with the store.
        data: [
             { id: 1, name: 'One' },
             { id: 2, name: 'Item 2' }, 
             { id: 3, name: 'Item Three' }
        ]
    },
    // If you specify data here it is provided to the tpl, but not properly bound to
    // the store. Unless the store knows about the data itemclick events won't work. 
    listeners: {
        beforecontainerclick: function (view) {
            console.log('beforecontainerclick');
        },
        beforeitemclick: function (view) {
            console.log('beforeitemclick');
        },
        containerclick: function (view) {
            console.log('containerclick');
        },
        itemclick: function (view) {
            console.log('itemclick');
        },
        selectionchange: function (view) {
            console.log('selectionchange');
        }
    }
});