4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../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 * Implement row based navigation via keyboard.
24 * Must synchronize across grid sections
26 Ext.define('Ext.selection.RowModel', {
27 extend: 'Ext.selection.Model',
28 alias: 'selection.rowmodel',
29 requires: ['Ext.util.KeyNav'],
31 <span id='Ext-selection-RowModel-property-deltaScroll'> /**
33 * Number of pixels to scroll to the left/right when pressing
38 <span id='Ext-selection-RowModel-cfg-enableKeyNav'> /**
39 </span> * @cfg {Boolean} enableKeyNav
41 * Turns on/off keyboard navigation within the grid. Defaults to true.
45 constructor: function(){
47 <span id='Ext-selection-RowModel-event-beforedeselect'> /**
48 </span> * @event beforedeselect
49 * Fired before a record is deselected. If any listener returns false, the
50 * deselection is cancelled.
51 * @param {Ext.selection.RowSelectionModel} this
52 * @param {Ext.data.Model} record The deselected record
53 * @param {Number} index The row index deselected
57 <span id='Ext-selection-RowModel-event-beforeselect'> /**
58 </span> * @event beforeselect
59 * Fired before a record is selected. If any listener returns false, the
60 * selection is cancelled.
61 * @param {Ext.selection.RowSelectionModel} this
62 * @param {Ext.data.Model} record The selected record
63 * @param {Number} index The row index selected
67 <span id='Ext-selection-RowModel-event-deselect'> /**
68 </span> * @event deselect
69 * Fired after a record is deselected
70 * @param {Ext.selection.RowSelectionModel} this
71 * @param {Ext.data.Model} record The deselected record
72 * @param {Number} index The row index deselected
76 <span id='Ext-selection-RowModel-event-select'> /**
77 </span> * @event select
78 * Fired after a record is selected
79 * @param {Ext.selection.RowSelectionModel} this
80 * @param {Ext.data.Model} record The selected record
81 * @param {Number} index The row index selected
85 this.callParent(arguments);
88 bindComponent: function(view) {
91 me.views = me.views || [];
93 me.bind(view.getStore(), true);
96 itemmousedown: me.onRowMouseDown,
100 if (me.enableKeyNav) {
105 initKeyNav: function(view) {
108 if (!view.rendered) {
109 view.on('render', Ext.Function.bind(me.initKeyNav, me, [view], 0), me, {single: true});
117 // view.el has tabIndex -1 to allow for
118 // keyboard events to be passed to it.
119 me.keyNav = new Ext.util.KeyNav(view.el, {
122 right: me.onKeyRight,
124 pageDown: me.onKeyPageDown,
125 pageUp: me.onKeyPageUp,
130 view.el.on(Ext.EventManager.getKeyEvent(), me.onKeyPress, me);
133 // Returns the number of rows currently visible on the screen or
134 // false if there were no rows. This assumes that all rows are
135 // of the same height and the first view is accurate.
136 getRowsVisible: function() {
137 var rowsVisible = false,
138 view = this.views[0],
139 row = view.getNode(0),
140 rowHeight, gridViewHeight;
143 rowHeight = Ext.fly(row).getHeight();
144 gridViewHeight = view.el.getHeight();
145 rowsVisible = Math.floor(gridViewHeight / rowHeight);
151 // go to last visible record in grid.
152 onKeyEnd: function(e, t) {
154 last = me.store.getAt(me.store.getCount() - 1);
158 me.selectRange(last, me.lastFocused || 0);
159 me.setLastFocused(last);
160 } else if (e.ctrlKey) {
161 me.setLastFocused(last);
168 // go to first visible record in grid.
169 onKeyHome: function(e, t) {
171 first = me.store.getAt(0);
175 me.selectRange(first, me.lastFocused || 0);
176 me.setLastFocused(first);
177 } else if (e.ctrlKey) {
178 me.setLastFocused(first);
180 me.doSelect(first, false);
185 // Go one page up from the lastFocused record in the grid.
186 onKeyPageUp: function(e, t) {
188 rowsVisible = me.getRowsVisible(),
195 selIdx = me.lastFocused ? me.store.indexOf(me.lastFocused) : 0;
196 prevIdx = selIdx - rowsVisible;
197 if (prevIdx < 0) {
200 prevRecord = me.store.getAt(prevIdx);
202 currRec = me.store.getAt(selIdx);
203 me.selectRange(prevRecord, currRec, e.ctrlKey, 'up');
204 me.setLastFocused(prevRecord);
205 } else if (e.ctrlKey) {
207 me.setLastFocused(prevRecord);
209 me.doSelect(prevRecord);
215 // Go one page down from the lastFocused record in the grid.
216 onKeyPageDown: function(e, t) {
218 rowsVisible = me.getRowsVisible(),
225 selIdx = me.lastFocused ? me.store.indexOf(me.lastFocused) : 0;
226 nextIdx = selIdx + rowsVisible;
227 if (nextIdx >= me.store.getCount()) {
228 nextIdx = me.store.getCount() - 1;
230 nextRecord = me.store.getAt(nextIdx);
232 currRec = me.store.getAt(selIdx);
233 me.selectRange(nextRecord, currRec, e.ctrlKey, 'down');
234 me.setLastFocused(nextRecord);
235 } else if (e.ctrlKey) {
236 // some browsers, this means go thru browser tabs
239 me.setLastFocused(nextRecord);
241 me.doSelect(nextRecord);
246 // Select/Deselect based on pressing Spacebar.
247 // Assumes a SIMPLE selectionmode style
248 onKeyPress: function(e, t) {
249 if (e.getKey() === e.SPACE) {
252 record = me.lastFocused;
255 if (me.isSelected(record)) {
256 me.doDeselect(record, false);
258 me.doSelect(record, true);
264 // Navigate one record up. This could be a selection or
265 // could be simply focusing a record for discontiguous
266 // selection. Provides bounds checking.
267 onKeyUp: function(e, t) {
270 idx = me.store.indexOf(me.lastFocused),
274 // needs to be the filtered count as thats what
276 record = me.store.getAt(idx - 1);
277 if (e.shiftKey && me.lastFocused) {
278 if (me.isSelected(me.lastFocused) && me.isSelected(record)) {
279 me.doDeselect(me.lastFocused, true);
280 me.setLastFocused(record);
281 } else if (!me.isSelected(me.lastFocused)) {
282 me.doSelect(me.lastFocused, true);
283 me.doSelect(record, true);
285 me.doSelect(record, true);
287 } else if (e.ctrlKey) {
288 me.setLastFocused(record);
291 //view.focusRow(idx - 1);
294 // There was no lastFocused record, and the user has pressed up
296 //else if (this.selected.getCount() == 0) {
298 // this.doSelect(record);
299 // //view.focusRow(idx - 1);
303 // Navigate one record down. This could be a selection or
304 // could be simply focusing a record for discontiguous
305 // selection. Provides bounds checking.
306 onKeyDown: function(e, t) {
309 idx = me.store.indexOf(me.lastFocused),
312 // needs to be the filtered count as thats what
314 if (idx + 1 < me.store.getCount()) {
315 record = me.store.getAt(idx + 1);
316 if (me.selected.getCount() === 0) {
318 //view.focusRow(idx + 1);
319 } else if (e.shiftKey && me.lastFocused) {
320 if (me.isSelected(me.lastFocused) && me.isSelected(record)) {
321 me.doDeselect(me.lastFocused, true);
322 me.setLastFocused(record);
323 } else if (!me.isSelected(me.lastFocused)) {
324 me.doSelect(me.lastFocused, true);
325 me.doSelect(record, true);
327 me.doSelect(record, true);
329 } else if (e.ctrlKey) {
330 me.setLastFocused(record);
333 //view.focusRow(idx + 1);
338 scrollByDeltaX: function(delta) {
339 var view = this.views[0],
341 hScroll = section.horizontalScroller;
344 hScroll.scrollByDeltaX(delta);
348 onKeyLeft: function(e, t) {
349 this.scrollByDeltaX(-this.deltaScroll);
352 onKeyRight: function(e, t) {
353 this.scrollByDeltaX(this.deltaScroll);
356 // Select the record with the event included so that
357 // we can take into account ctrlKey, shiftKey, etc
358 onRowMouseDown: function(view, record, item, index, e) {
360 this.selectWithEvent(record, e);
363 // Allow the GridView to update the UI by
364 // adding/removing a CSS class from the row.
365 onSelectChange: function(record, isSelected, suppressEvent, commitFn) {
368 viewsLn = views.length,
370 rowIdx = store.indexOf(record),
371 eventName = isSelected ? 'select' : 'deselect',
374 if ((suppressEvent || me.fireEvent('before' + eventName, me, record, rowIdx)) !== false &&
375 commitFn() !== false) {
377 for (; i < viewsLn; i++) {
379 views[i].onRowSelect(rowIdx, suppressEvent);
381 views[i].onRowDeselect(rowIdx, suppressEvent);
385 if (!suppressEvent) {
386 me.fireEvent(eventName, me, record, rowIdx);
391 // Provide indication of what row was last focused via
393 onLastFocusChanged: function(oldFocused, newFocused, supressFocus) {
394 var views = this.views,
395 viewsLn = views.length,
401 rowIdx = store.indexOf(oldFocused);
403 for (; i < viewsLn; i++) {
404 views[i].onRowFocus(rowIdx, false);
410 rowIdx = store.indexOf(newFocused);
412 for (i = 0; i < viewsLn; i++) {
413 views[i].onRowFocus(rowIdx, true, supressFocus);
419 onEditorTab: function(editingPlugin, e) {
422 record = editingPlugin.getActiveRecord(),
423 header = editingPlugin.getActiveColumn(),
424 position = view.getPosition(record, header),
425 direction = e.shiftKey ? 'left' : 'right',
426 newPosition = view.walkCells(position, direction, e, this.preventWrap);
429 editingPlugin.startEditByPosition(newPosition);
433 selectByPosition: function(position) {
434 var record = this.store.getAt(position.row);