4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-selection-DataViewModel'>/**
19 </span> * @class Ext.selection.DataViewModel
22 Ext.define('Ext.selection.DataViewModel', {
23 extend: 'Ext.selection.Model',
25 requires: ['Ext.util.KeyNav'],
27 deselectOnContainerClick: true,
29 <span id='Ext-selection-DataViewModel-cfg-enableKeyNav'> /**
30 </span> * @cfg {Boolean} enableKeyNav
32 * Turns on/off keyboard navigation within the DataView.
36 constructor: function(cfg){
38 <span id='Ext-selection-DataViewModel-event-beforedeselect'> /**
39 </span> * @event beforedeselect
40 * Fired before a record is deselected. If any listener returns false, the
41 * deselection is cancelled.
42 * @param {Ext.selection.DataViewModel} this
43 * @param {Ext.data.Model} record The deselected record
47 <span id='Ext-selection-DataViewModel-event-beforeselect'> /**
48 </span> * @event beforeselect
49 * Fired before a record is selected. If any listener returns false, the
50 * selection is cancelled.
51 * @param {Ext.selection.DataViewModel} this
52 * @param {Ext.data.Model} record The selected record
56 <span id='Ext-selection-DataViewModel-event-deselect'> /**
57 </span> * @event deselect
58 * Fired after a record is deselected
59 * @param {Ext.selection.DataViewModel} this
60 * @param {Ext.data.Model} record The deselected record
64 <span id='Ext-selection-DataViewModel-event-select'> /**
65 </span> * @event select
66 * Fired after a record is selected
67 * @param {Ext.selection.DataViewModel} this
68 * @param {Ext.data.Model} record The selected record
72 this.callParent(arguments);
75 bindComponent: function(view) {
83 me.bind(view.getStore());
85 view.on(view.triggerEvent, me.onItemClick, me);
86 view.on(view.triggerCtEvent, me.onContainerClick, me);
88 view.on(eventListeners);
90 if (me.enableKeyNav) {
95 onItemClick: function(view, record, item, index, e) {
96 this.selectWithEvent(record, e);
99 onContainerClick: function() {
100 if (this.deselectOnContainerClick) {
105 initKeyNav: function(view) {
108 if (!view.rendered) {
109 view.on('render', Ext.Function.bind(me.initKeyNav, me, [view], 0), me, {single: true});
116 me.keyNav = Ext.create('Ext.util.KeyNav', view.el, {
117 down: Ext.pass(me.onNavKey, [1], me),
118 right: Ext.pass(me.onNavKey, [1], me),
119 left: Ext.pass(me.onNavKey, [-1], me),
120 up: Ext.pass(me.onNavKey, [-1], me),
125 onNavKey: function(step) {
129 selected = me.getSelection()[0],
130 numRecords = me.view.store.getCount(),
134 idx = view.indexOf(view.getNode(selected)) + step;
140 idx = numRecords - 1;
141 } else if (idx >= numRecords) {
148 // Allow the DataView to update the ui
149 onSelectChange: function(record, isSelected, suppressEvent, commitFn) {
152 eventName = isSelected ? 'select' : 'deselect';
154 if ((suppressEvent || me.fireEvent('before' + eventName, me, record)) !== false &&
155 commitFn() !== false) {
158 view.onItemSelect(record);
160 view.onItemDeselect(record);
163 if (!suppressEvent) {
164 me.fireEvent(eventName, me, record);
170 Ext.destroy(this.keyNav);