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-deselect'> /**
48 </span> * @event deselect
49 * Fired after a record is deselected
50 * @param {Ext.selection.RowSelectionModel} this
51 * @param {Ext.data.Model} record The deselected record
52 * @param {Number} index The row index deselected
56 <span id='Ext-selection-RowModel-event-select'> /**
57 </span> * @event select
58 * Fired after a record is selected
59 * @param {Ext.selection.RowSelectionModel} this
60 * @param {Ext.data.Model} record The selected record
61 * @param {Number} index The row index selected
65 this.callParent(arguments);
68 bindComponent: function(view) {
71 me.views = me.views || [];
73 me.bind(view.getStore(), true);
76 itemmousedown: me.onRowMouseDown,
80 if (me.enableKeyNav) {
85 initKeyNav: function(view) {
89 view.on('render', Ext.Function.bind(me.initKeyNav, me, [view], 0), me, {single: true});
97 // view.el has tabIndex -1 to allow for
98 // keyboard events to be passed to it.
99 me.keyNav = new Ext.util.KeyNav(view.el, {
102 right: me.onKeyRight,
104 pageDown: me.onKeyPageDown,
105 pageUp: me.onKeyPageUp,
110 view.el.on(Ext.EventManager.getKeyEvent(), me.onKeyPress, me);
113 // Returns the number of rows currently visible on the screen or
114 // false if there were no rows. This assumes that all rows are
115 // of the same height and the first view is accurate.
116 getRowsVisible: function() {
117 var rowsVisible = false,
118 view = this.views[0],
119 row = view.getNode(0),
120 rowHeight, gridViewHeight;
123 rowHeight = Ext.fly(row).getHeight();
124 gridViewHeight = view.el.getHeight();
125 rowsVisible = Math.floor(gridViewHeight / rowHeight);
131 // go to last visible record in grid.
132 onKeyEnd: function(e, t) {
134 last = me.store.getAt(me.store.getCount() - 1);
138 me.selectRange(last, me.lastFocused || 0);
139 me.setLastFocused(last);
140 } else if (e.ctrlKey) {
141 me.setLastFocused(last);
148 // go to first visible record in grid.
149 onKeyHome: function(e, t) {
151 first = me.store.getAt(0);
155 me.selectRange(first, me.lastFocused || 0);
156 me.setLastFocused(first);
157 } else if (e.ctrlKey) {
158 me.setLastFocused(first);
160 me.doSelect(first, false);
165 // Go one page up from the lastFocused record in the grid.
166 onKeyPageUp: function(e, t) {
168 rowsVisible = me.getRowsVisible(),
175 selIdx = me.lastFocused ? me.store.indexOf(me.lastFocused) : 0;
176 prevIdx = selIdx - rowsVisible;
177 if (prevIdx < 0) {
180 prevRecord = me.store.getAt(prevIdx);
182 currRec = me.store.getAt(selIdx);
183 me.selectRange(prevRecord, currRec, e.ctrlKey, 'up');
184 me.setLastFocused(prevRecord);
185 } else if (e.ctrlKey) {
187 me.setLastFocused(prevRecord);
189 me.doSelect(prevRecord);
195 // Go one page down from the lastFocused record in the grid.
196 onKeyPageDown: function(e, t) {
198 rowsVisible = me.getRowsVisible(),
205 selIdx = me.lastFocused ? me.store.indexOf(me.lastFocused) : 0;
206 nextIdx = selIdx + rowsVisible;
207 if (nextIdx >= me.store.getCount()) {
208 nextIdx = me.store.getCount() - 1;
210 nextRecord = me.store.getAt(nextIdx);
212 currRec = me.store.getAt(selIdx);
213 me.selectRange(nextRecord, currRec, e.ctrlKey, 'down');
214 me.setLastFocused(nextRecord);
215 } else if (e.ctrlKey) {
216 // some browsers, this means go thru browser tabs
219 me.setLastFocused(nextRecord);
221 me.doSelect(nextRecord);
226 // Select/Deselect based on pressing Spacebar.
227 // Assumes a SIMPLE selectionmode style
228 onKeyPress: function(e, t) {
229 if (e.getKey() === e.SPACE) {
232 record = me.lastFocused;
235 if (me.isSelected(record)) {
236 me.doDeselect(record, false);
238 me.doSelect(record, true);
244 // Navigate one record up. This could be a selection or
245 // could be simply focusing a record for discontiguous
246 // selection. Provides bounds checking.
247 onKeyUp: function(e, t) {
250 idx = me.store.indexOf(me.lastFocused),
254 // needs to be the filtered count as thats what
256 record = me.store.getAt(idx - 1);
257 if (e.shiftKey && me.lastFocused) {
258 if (me.isSelected(me.lastFocused) && me.isSelected(record)) {
259 me.doDeselect(me.lastFocused, true);
260 me.setLastFocused(record);
261 } else if (!me.isSelected(me.lastFocused)) {
262 me.doSelect(me.lastFocused, true);
263 me.doSelect(record, true);
265 me.doSelect(record, true);
267 } else if (e.ctrlKey) {
268 me.setLastFocused(record);
271 //view.focusRow(idx - 1);
274 // There was no lastFocused record, and the user has pressed up
276 //else if (this.selected.getCount() == 0) {
278 // this.doSelect(record);
279 // //view.focusRow(idx - 1);
283 // Navigate one record down. This could be a selection or
284 // could be simply focusing a record for discontiguous
285 // selection. Provides bounds checking.
286 onKeyDown: function(e, t) {
289 idx = me.store.indexOf(me.lastFocused),
292 // needs to be the filtered count as thats what
294 if (idx + 1 < me.store.getCount()) {
295 record = me.store.getAt(idx + 1);
296 if (me.selected.getCount() === 0) {
298 //view.focusRow(idx + 1);
299 } else if (e.shiftKey && me.lastFocused) {
300 if (me.isSelected(me.lastFocused) && me.isSelected(record)) {
301 me.doDeselect(me.lastFocused, true);
302 me.setLastFocused(record);
303 } else if (!me.isSelected(me.lastFocused)) {
304 me.doSelect(me.lastFocused, true);
305 me.doSelect(record, true);
307 me.doSelect(record, true);
309 } else if (e.ctrlKey) {
310 me.setLastFocused(record);
313 //view.focusRow(idx + 1);
318 scrollByDeltaX: function(delta) {
319 var view = this.views[0],
321 hScroll = section.horizontalScroller;
324 hScroll.scrollByDeltaX(delta);
328 onKeyLeft: function(e, t) {
329 this.scrollByDeltaX(-this.deltaScroll);
332 onKeyRight: function(e, t) {
333 this.scrollByDeltaX(this.deltaScroll);
336 // Select the record with the event included so that
337 // we can take into account ctrlKey, shiftKey, etc
338 onRowMouseDown: function(view, record, item, index, e) {
340 this.selectWithEvent(record, e);
343 // Allow the GridView to update the UI by
344 // adding/removing a CSS class from the row.
345 onSelectChange: function(record, isSelected, suppressEvent) {
348 viewsLn = views.length,
350 rowIdx = store.indexOf(record),
353 for (; i < viewsLn; i++) {
355 views[i].onRowSelect(rowIdx, suppressEvent);
356 if (!suppressEvent) {
357 me.fireEvent('select', me, record, rowIdx);
360 views[i].onRowDeselect(rowIdx, suppressEvent);
361 if (!suppressEvent) {
362 me.fireEvent('deselect', me, record, rowIdx);
368 // Provide indication of what row was last focused via
370 onLastFocusChanged: function(oldFocused, newFocused, supressFocus) {
371 var views = this.views,
372 viewsLn = views.length,
378 rowIdx = store.indexOf(oldFocused);
380 for (; i < viewsLn; i++) {
381 views[i].onRowFocus(rowIdx, false);
387 rowIdx = store.indexOf(newFocused);
389 for (i = 0; i < viewsLn; i++) {
390 views[i].onRowFocus(rowIdx, true, supressFocus);
396 onEditorTab: function(editingPlugin, e) {
399 record = editingPlugin.getActiveRecord(),
400 header = editingPlugin.getActiveColumn(),
401 position = view.getPosition(record, header),
402 direction = e.shiftKey ? 'left' : 'right',
403 newPosition = view.walkCells(position, direction, e, this.preventWrap);
406 editingPlugin.startEditByPosition(newPosition);
410 selectByPosition: function(position) {
411 var record = this.store.getAt(position.row);