Handling events in DataView

Once we have our DataView defined, we are going to see some basic event handling for it. To do this, we need to add some new properties to our view definition so that we can assign events:

  var myDataview = Ext.create('Ext.view.View', {
    store: myStore,
    tpl: myTpl,
    padding: 6,
    itemSelector: 'div.user', //Step 1
    emptyText: '<b>No users available</b>'
  });

We added the itemSelector property (Step 1). It defines which DOM node item will be used to select each item (data model) with which the DataView will be working.

You can use CSS selectors to define the itemSelector property.

And now, let's add the event listener:

var myDataview = Ext.create('Ext.view.View', { store: myStore, tpl: myTpl, padding: 6, itemSelector: 'div.user', ...

Get Learning Ext JS - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.