Guide applies to: modern
Introduction
In this lab, you’ll create the Dataview for the thumbnails.
1.Create the dataview
Create the file app/desktop/src/view/TunesView.js
with this code:
Ext.define('ModernTunes.view.TunesView', {
extend: 'Ext.dataview.DataView',
xtype: 'tunesview',
scrollable: true,
layout: {
type: 'box',
pack: 'space-around',
wrap: true
},
itemTpl: [
'<figure>',
'<div class="thumbnail" style="background-image:url(\'{image}\')"></div>',
'<figcaption><div class=\'title\'>{title}</div><div class=\'artist\'>{artist}</div></figcaption>',
'</figure>'
]
});
The itemTpl allows the injection of html and css around the data available per record.
2.Use the dataview
Edit app/desktop/src/view/main/MainView.js
and:
- Add ModernTunes.view.TunesView to the requires array to indicate this file is ‘required’ for the application’s eventual build
- Make sure requires array includes MainViewController and MainViewModel
requires: [
'ModernTunes.view.main.MainViewController',
'ModernTunes.view.main.MainViewModel',
'ModernTunes.view.TunesView'
],
- Replace the html placeholder we had for the dataview in the items array for
Thumbnails
with the xtype assigned to the TuneView class, calledtunesview
. Later on we will do the same with the grid.
xtype: 'tunesview',
In same
Thumbnails
object, bind the item’s store property to {tunes} store in MainViewModel.jsbind: {
store: '{tunes}'
}
Save your changes and you should see the scrollable list of top iTunes music videos. This list is not styled and we will work on that in the next section.
3.Here’s the code for MainView
If you’d like to check your work, app/desktop/src/view/main/MainView.js
should end up looking something like this.
Ext.define("ModernTunes.view.main.MainView", {
extend: "Ext.tab.Panel",
xtype: 'mainview',
requires: [
'ModernTunes.view.main.MainViewController',
'ModernTunes.view.main.MainViewModel',
'ModernTunes.view.TunesView'
],
controller: "mainviewcontroller",
viewModel: {
type: "mainviewmodel"
},
tabBarPosition: 'bottom',
items: [{
title: "Thumbnails",
xtype: 'tunesview',
bind: {
store: '{tunes}'
}
}, {
title: "Grid",
html : "<h1>tunes grid </h1>"
}]
});
4.Sort the data
It would be nice to see the data sorted by title within artist. To do that, edit app/desktop/src/view/main/MainViewModel.js
and modify the +tunes+ store like this:
stores: {
tunes: {
model: 'ModernTunes.model.Tune',
autoLoad: true,
sorters: ['artist', 'title']
}
}
Save, and you should see the thumbnails sorted accordingly.