Guide applies to: modern

    A dataview renders a template for every record in a store. The items can be associated with a CSS style. You can bind to the dataview’s selection, and listen to events.

    • itemCls is applied to each item
    • overItemCls is applied as you mouse over an item
    • selectedItemCls is applied when you select an item

      Expand Code

      JS Run

      1. Ext.define('MyApp.view.Main', {
      2. //extend: 'Ext.view.View', // classic
      3. extend: 'Ext.dataview.DataView', // modern
      4. itemTpl: '<img src="{image}">',
      5. cls: 'movies',
      6. itemCls: 'movie',
      7. overItemCls: 'over',
      8. selectedItemCls: 'selected',
      9. listeners: {
      10. itemtap: function(view, record){
      11. // You could listen to select too, but that's only fired as the selection
      12. // changes, so you wouldn't detect clicking on the same item twice.
      13. Ext.toast({
      14. html: 'You clicked on ' + record.get('movie'),
      15. align: 't'
      16. });
      17. }
      18. },
      19. store: {
      20. model: getModel(),
      21. autoLoad: true
      22. },
      23. emptyText: 'An Internet connection is needed to load titles from iTunes.'
      24. });
      25. Ext.application({
      26. name: 'MyApp',
      27. mainView: 'MyApp.view.Main'
      28. });
      29. function getModel(){
      30. Ext.define('MyApp.model.Movie', {
      31. extend: 'Ext.data.Model',
      32. fields: [{
      33. name: 'id',
      34. mapping: 'id.attributes["im:id"]'
      35. }, {
      36. name: 'movie',
      37. mapping: '["im:name"].label'
      38. }, {
      39. name: 'image',
      40. mapping: '["im:image"][2].label'
      41. }],
      42. proxy: {
      43. type: 'jsonp',
      44. url: 'https://itunes.apple.com/us/rss/topmovies/limit=5/json',
      45. reader: {
      46. type: 'json',
      47. rootProperty: 'feed.entry'
      48. }
      49. }
      50. });
      51. return 'MyApp.model.Movie';
      52. }