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-RowModel'>/**
19 </span> * @class Ext.selection.RowModel
20 * @extends Ext.selection.Model
22 Ext.define('Ext.selection.RowModel', {
23 extend: 'Ext.selection.Model',
24 alias: 'selection.rowmodel',
25 requires: ['Ext.util.KeyNav'],
27 <span id='Ext-selection-RowModel-property-deltaScroll'> /**
29 * Number of pixels to scroll to the left/right when pressing
34 <span id='Ext-selection-RowModel-cfg-enableKeyNav'> /**
35 </span> * @cfg {Boolean} enableKeyNav
37 * Turns on/off keyboard navigation within the grid.
41 <span id='Ext-selection-RowModel-cfg-ignoreRightMouseSelection'> /**
42 </span> * @cfg {Boolean} [ignoreRightMouseSelection=true]
43 * True to ignore selections that are made when using the right mouse button if there are
44 * records that are already selected. If no records are selected, selection will continue
47 ignoreRightMouseSelection: true,
49 constructor: function(){
51 <span id='Ext-selection-RowModel-event-beforedeselect'> /**
52 </span> * @event beforedeselect
53 * Fired before a record is deselected. If any listener returns false, the
54 * deselection is cancelled.
55 * @param {Ext.selection.RowModel} this
56 * @param {Ext.data.Model} record The deselected record
57 * @param {Number} index The row index deselected
61 <span id='Ext-selection-RowModel-event-beforeselect'> /**
62 </span> * @event beforeselect
63 * Fired before a record is selected. If any listener returns false, the
64 * selection is cancelled.
65 * @param {Ext.selection.RowModel} this
66 * @param {Ext.data.Model} record The selected record
67 * @param {Number} index The row index selected
71 <span id='Ext-selection-RowModel-event-deselect'> /**
72 </span> * @event deselect
73 * Fired after a record is deselected
74 * @param {Ext.selection.RowModel} this
75 * @param {Ext.data.Model} record The deselected record
76 * @param {Number} index The row index deselected
80 <span id='Ext-selection-RowModel-event-select'> /**
81 </span> * @event select
82 * Fired after a record is selected
83 * @param {Ext.selection.RowModel} this
84 * @param {Ext.data.Model} record The selected record
85 * @param {Number} index The row index selected
89 this.callParent(arguments);
92 bindComponent: function(view) {
95 me.views = me.views || [];
97 me.bind(view.getStore(), true);
100 itemmousedown: me.onRowMouseDown,
104 if (me.enableKeyNav) {
109 initKeyNav: function(view) {
112 if (!view.rendered) {
113 view.on('render', Ext.Function.bind(me.initKeyNav, me, [view], 0), me, {single: true});
121 // view.el has tabIndex -1 to allow for
122 // keyboard events to be passed to it.
123 me.keyNav = new Ext.util.KeyNav(view.el, {
126 right: me.onKeyRight,
128 pageDown: me.onKeyPageDown,
129 pageUp: me.onKeyPageUp,
134 view.el.on(Ext.EventManager.getKeyEvent(), me.onKeyPress, me);
137 // Returns the number of rows currently visible on the screen or
138 // false if there were no rows. This assumes that all rows are
139 // of the same height and the first view is accurate.
140 getRowsVisible: function() {
141 var rowsVisible = false,
142 view = this.views[0],
143 row = view.getNode(0),
144 rowHeight, gridViewHeight;
147 rowHeight = Ext.fly(row).getHeight();
148 gridViewHeight = view.el.getHeight();
149 rowsVisible = Math.floor(gridViewHeight / rowHeight);
155 // go to last visible record in grid.
156 onKeyEnd: function(e, t) {
158 last = me.store.getAt(me.store.getCount() - 1);
162 me.selectRange(last, me.lastFocused || 0);
163 me.setLastFocused(last);
164 } else if (e.ctrlKey) {
165 me.setLastFocused(last);
172 // go to first visible record in grid.
173 onKeyHome: function(e, t) {
175 first = me.store.getAt(0);
179 me.selectRange(first, me.lastFocused || 0);
180 me.setLastFocused(first);
181 } else if (e.ctrlKey) {
182 me.setLastFocused(first);
184 me.doSelect(first, false);
189 // Go one page up from the lastFocused record in the grid.
190 onKeyPageUp: function(e, t) {
192 rowsVisible = me.getRowsVisible(),
199 selIdx = me.lastFocused ? me.store.indexOf(me.lastFocused) : 0;
200 prevIdx = selIdx - rowsVisible;
201 if (prevIdx < 0) {
204 prevRecord = me.store.getAt(prevIdx);
206 currRec = me.store.getAt(selIdx);
207 me.selectRange(prevRecord, currRec, e.ctrlKey, 'up');
208 me.setLastFocused(prevRecord);
209 } else if (e.ctrlKey) {
211 me.setLastFocused(prevRecord);
213 me.doSelect(prevRecord);
219 // Go one page down from the lastFocused record in the grid.
220 onKeyPageDown: function(e, t) {
222 rowsVisible = me.getRowsVisible(),
229 selIdx = me.lastFocused ? me.store.indexOf(me.lastFocused) : 0;
230 nextIdx = selIdx + rowsVisible;
231 if (nextIdx >= me.store.getCount()) {
232 nextIdx = me.store.getCount() - 1;
234 nextRecord = me.store.getAt(nextIdx);
236 currRec = me.store.getAt(selIdx);
237 me.selectRange(nextRecord, currRec, e.ctrlKey, 'down');
238 me.setLastFocused(nextRecord);
239 } else if (e.ctrlKey) {
240 // some browsers, this means go thru browser tabs
243 me.setLastFocused(nextRecord);
245 me.doSelect(nextRecord);
250 // Select/Deselect based on pressing Spacebar.
251 // Assumes a SIMPLE selectionmode style
252 onKeyPress: function(e, t) {
253 if (e.getKey() === e.SPACE) {
256 record = me.lastFocused;
259 if (me.isSelected(record)) {
260 me.doDeselect(record, false);
262 me.doSelect(record, true);
268 // Navigate one record up. This could be a selection or
269 // could be simply focusing a record for discontiguous
270 // selection. Provides bounds checking.
271 onKeyUp: function(e, t) {
274 idx = me.store.indexOf(me.lastFocused),
278 // needs to be the filtered count as thats what
280 record = me.store.getAt(idx - 1);
281 if (e.shiftKey && me.lastFocused) {
282 if (me.isSelected(me.lastFocused) && me.isSelected(record)) {
283 me.doDeselect(me.lastFocused, true);
284 me.setLastFocused(record);
285 } else if (!me.isSelected(me.lastFocused)) {
286 me.doSelect(me.lastFocused, true);
287 me.doSelect(record, true);
289 me.doSelect(record, true);
291 } else if (e.ctrlKey) {
292 me.setLastFocused(record);
295 //view.focusRow(idx - 1);
298 // There was no lastFocused record, and the user has pressed up
300 //else if (this.selected.getCount() == 0) {
302 // this.doSelect(record);
303 // //view.focusRow(idx - 1);
307 // Navigate one record down. This could be a selection or
308 // could be simply focusing a record for discontiguous
309 // selection. Provides bounds checking.
310 onKeyDown: function(e, t) {
313 idx = me.store.indexOf(me.lastFocused),
316 // needs to be the filtered count as thats what
318 if (idx + 1 < me.store.getCount()) {
319 record = me.store.getAt(idx + 1);
320 if (me.selected.getCount() === 0) {
322 //view.focusRow(idx + 1);
323 } else if (e.shiftKey && me.lastFocused) {
324 if (me.isSelected(me.lastFocused) && me.isSelected(record)) {
325 me.doDeselect(me.lastFocused, true);
326 me.setLastFocused(record);
327 } else if (!me.isSelected(me.lastFocused)) {
328 me.doSelect(me.lastFocused, true);
329 me.doSelect(record, true);
331 me.doSelect(record, true);
333 } else if (e.ctrlKey) {
334 me.setLastFocused(record);
337 //view.focusRow(idx + 1);
342 scrollByDeltaX: function(delta) {
343 var view = this.views[0],
345 hScroll = section.horizontalScroller;
348 hScroll.scrollByDeltaX(delta);
352 onKeyLeft: function(e, t) {
353 this.scrollByDeltaX(-this.deltaScroll);
356 onKeyRight: function(e, t) {
357 this.scrollByDeltaX(this.deltaScroll);
360 // Select the record with the event included so that
361 // we can take into account ctrlKey, shiftKey, etc
362 onRowMouseDown: function(view, record, item, index, e) {
364 if (!this.allowRightMouseSelection(e)) {
367 this.selectWithEvent(record, e);
370 <span id='Ext-selection-RowModel-method-allowRightMouseSelection'> /**
371 </span> * Checks whether a selection should proceed based on the ignoreRightMouseSelection
374 * @param {Ext.EventObject} e The event
375 * @return {Boolean} False if the selection should not proceed
377 allowRightMouseSelection: function(e) {
378 var disallow = this.ignoreRightMouseSelection && e.button !== 0;
380 disallow = this.hasSelection();
385 // Allow the GridView to update the UI by
386 // adding/removing a CSS class from the row.
387 onSelectChange: function(record, isSelected, suppressEvent, commitFn) {
390 viewsLn = views.length,
392 rowIdx = store.indexOf(record),
393 eventName = isSelected ? 'select' : 'deselect',
396 if ((suppressEvent || me.fireEvent('before' + eventName, me, record, rowIdx)) !== false &&
397 commitFn() !== false) {
399 for (; i < viewsLn; i++) {
401 views[i].onRowSelect(rowIdx, suppressEvent);
403 views[i].onRowDeselect(rowIdx, suppressEvent);
407 if (!suppressEvent) {
408 me.fireEvent(eventName, me, record, rowIdx);
413 // Provide indication of what row was last focused via
415 onLastFocusChanged: function(oldFocused, newFocused, supressFocus) {
416 var views = this.views,
417 viewsLn = views.length,
423 rowIdx = store.indexOf(oldFocused);
425 for (; i < viewsLn; i++) {
426 views[i].onRowFocus(rowIdx, false);
432 rowIdx = store.indexOf(newFocused);
434 for (i = 0; i < viewsLn; i++) {
435 views[i].onRowFocus(rowIdx, true, supressFocus);
441 onEditorTab: function(editingPlugin, e) {
444 record = editingPlugin.getActiveRecord(),
445 header = editingPlugin.getActiveColumn(),
446 position = view.getPosition(record, header),
447 direction = e.shiftKey ? 'left' : 'right',
448 newPosition = view.walkCells(position, direction, e, this.preventWrap);
451 editingPlugin.startEditByPosition(newPosition);
455 selectByPosition: function(position) {
456 var record = this.store.getAt(position.row);