1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-selection.RowModel'>/**
2 </span> * @class Ext.selection.RowModel
3 * @extends Ext.selection.Model
5 * Implement row based navigation via keyboard.
7 * Must synchronize across grid sections
9 Ext.define('Ext.selection.RowModel', {
10 extend: 'Ext.selection.Model',
11 alias: 'selection.rowmodel',
12 requires: ['Ext.util.KeyNav'],
14 <span id='Ext-selection.RowModel-property-deltaScroll'> /**
16 * Number of pixels to scroll to the left/right when pressing
21 <span id='Ext-selection.RowModel-cfg-enableKeyNav'> /**
22 </span> * @cfg {Boolean} enableKeyNav
24 * Turns on/off keyboard navigation within the grid. Defaults to true.
28 constructor: function(){
30 <span id='Ext-selection.RowModel-event-deselect'> /**
31 </span> * @event deselect
32 * Fired after a record is deselected
33 * @param {Ext.selection.RowSelectionModel} this
34 * @param {Ext.data.Model} record The deselected record
35 * @param {Number} index The row index deselected
39 <span id='Ext-selection.RowModel-event-select'> /**
40 </span> * @event select
41 * Fired after a record is selected
42 * @param {Ext.selection.RowSelectionModel} this
43 * @param {Ext.data.Model} record The selected record
44 * @param {Number} index The row index selected
48 this.callParent(arguments);
51 bindComponent: function(view) {
54 me.views = me.views || [];
56 me.bind(view.getStore(), true);
59 itemmousedown: me.onRowMouseDown,
63 if (me.enableKeyNav) {
68 initKeyNav: function(view) {
72 view.on('render', Ext.Function.bind(me.initKeyNav, me, [view], 0), me, {single: true});
80 // view.el has tabIndex -1 to allow for
81 // keyboard events to be passed to it.
82 me.keyNav = new Ext.util.KeyNav(view.el, {
87 pageDown: me.onKeyPageDown,
88 pageUp: me.onKeyPageUp,
93 view.el.on(Ext.EventManager.getKeyEvent(), me.onKeyPress, me);
96 // Returns the number of rows currently visible on the screen or
97 // false if there were no rows. This assumes that all rows are
98 // of the same height and the first view is accurate.
99 getRowsVisible: function() {
100 var rowsVisible = false,
101 view = this.views[0],
102 row = view.getNode(0),
103 rowHeight, gridViewHeight;
106 rowHeight = Ext.fly(row).getHeight();
107 gridViewHeight = view.el.getHeight();
108 rowsVisible = Math.floor(gridViewHeight / rowHeight);
114 // go to last visible record in grid.
115 onKeyEnd: function(e, t) {
117 last = me.store.getAt(me.store.getCount() - 1);
121 me.selectRange(last, me.lastFocused || 0);
122 me.setLastFocused(last);
123 } else if (e.ctrlKey) {
124 me.setLastFocused(last);
131 // go to first visible record in grid.
132 onKeyHome: function(e, t) {
134 first = me.store.getAt(0);
138 me.selectRange(first, me.lastFocused || 0);
139 me.setLastFocused(first);
140 } else if (e.ctrlKey) {
141 me.setLastFocused(first);
143 me.doSelect(first, false);
148 // Go one page up from the lastFocused record in the grid.
149 onKeyPageUp: function(e, t) {
151 rowsVisible = me.getRowsVisible(),
158 selIdx = me.lastFocused ? me.store.indexOf(me.lastFocused) : 0;
159 prevIdx = selIdx - rowsVisible;
160 if (prevIdx < 0) {
163 prevRecord = me.store.getAt(prevIdx);
165 currRec = me.store.getAt(selIdx);
166 me.selectRange(prevRecord, currRec, e.ctrlKey, 'up');
167 me.setLastFocused(prevRecord);
168 } else if (e.ctrlKey) {
170 me.setLastFocused(prevRecord);
172 me.doSelect(prevRecord);
178 // Go one page down from the lastFocused record in the grid.
179 onKeyPageDown: function(e, t) {
181 rowsVisible = me.getRowsVisible(),
188 selIdx = me.lastFocused ? me.store.indexOf(me.lastFocused) : 0;
189 nextIdx = selIdx + rowsVisible;
190 if (nextIdx >= me.store.getCount()) {
191 nextIdx = me.store.getCount() - 1;
193 nextRecord = me.store.getAt(nextIdx);
195 currRec = me.store.getAt(selIdx);
196 me.selectRange(nextRecord, currRec, e.ctrlKey, 'down');
197 me.setLastFocused(nextRecord);
198 } else if (e.ctrlKey) {
199 // some browsers, this means go thru browser tabs
202 me.setLastFocused(nextRecord);
204 me.doSelect(nextRecord);
209 // Select/Deselect based on pressing Spacebar.
210 // Assumes a SIMPLE selectionmode style
211 onKeyPress: function(e, t) {
212 if (e.getKey() === e.SPACE) {
215 record = me.lastFocused;
218 if (me.isSelected(record)) {
219 me.doDeselect(record, false);
221 me.doSelect(record, true);
227 // Navigate one record up. This could be a selection or
228 // could be simply focusing a record for discontiguous
229 // selection. Provides bounds checking.
230 onKeyUp: function(e, t) {
233 idx = me.store.indexOf(me.lastFocused),
237 // needs to be the filtered count as thats what
239 record = me.store.getAt(idx - 1);
240 if (e.shiftKey && me.lastFocused) {
241 if (me.isSelected(me.lastFocused) && me.isSelected(record)) {
242 me.doDeselect(me.lastFocused, true);
243 me.setLastFocused(record);
244 } else if (!me.isSelected(me.lastFocused)) {
245 me.doSelect(me.lastFocused, true);
246 me.doSelect(record, true);
248 me.doSelect(record, true);
250 } else if (e.ctrlKey) {
251 me.setLastFocused(record);
254 //view.focusRow(idx - 1);
257 // There was no lastFocused record, and the user has pressed up
259 //else if (this.selected.getCount() == 0) {
261 // this.doSelect(record);
262 // //view.focusRow(idx - 1);
266 // Navigate one record down. This could be a selection or
267 // could be simply focusing a record for discontiguous
268 // selection. Provides bounds checking.
269 onKeyDown: function(e, t) {
272 idx = me.store.indexOf(me.lastFocused),
275 // needs to be the filtered count as thats what
277 if (idx + 1 < me.store.getCount()) {
278 record = me.store.getAt(idx + 1);
279 if (me.selected.getCount() === 0) {
281 //view.focusRow(idx + 1);
282 } else if (e.shiftKey && me.lastFocused) {
283 if (me.isSelected(me.lastFocused) && me.isSelected(record)) {
284 me.doDeselect(me.lastFocused, true);
285 me.setLastFocused(record);
286 } else if (!me.isSelected(me.lastFocused)) {
287 me.doSelect(me.lastFocused, true);
288 me.doSelect(record, true);
290 me.doSelect(record, true);
292 } else if (e.ctrlKey) {
293 me.setLastFocused(record);
296 //view.focusRow(idx + 1);
301 scrollByDeltaX: function(delta) {
302 var view = this.views[0],
304 hScroll = section.horizontalScroller;
307 hScroll.scrollByDeltaX(delta);
311 onKeyLeft: function(e, t) {
312 this.scrollByDeltaX(-this.deltaScroll);
315 onKeyRight: function(e, t) {
316 this.scrollByDeltaX(this.deltaScroll);
319 // Select the record with the event included so that
320 // we can take into account ctrlKey, shiftKey, etc
321 onRowMouseDown: function(view, record, item, index, e) {
323 this.selectWithEvent(record, e);
326 // Allow the GridView to update the UI by
327 // adding/removing a CSS class from the row.
328 onSelectChange: function(record, isSelected, suppressEvent) {
331 viewsLn = views.length,
333 rowIdx = store.indexOf(record),
336 for (; i < viewsLn; i++) {
338 views[i].onRowSelect(rowIdx, suppressEvent);
339 if (!suppressEvent) {
340 me.fireEvent('select', me, record, rowIdx);
343 views[i].onRowDeselect(rowIdx, suppressEvent);
344 if (!suppressEvent) {
345 me.fireEvent('deselect', me, record, rowIdx);
351 // Provide indication of what row was last focused via
353 onLastFocusChanged: function(oldFocused, newFocused, supressFocus) {
354 var views = this.views,
355 viewsLn = views.length,
361 rowIdx = store.indexOf(oldFocused);
363 for (; i < viewsLn; i++) {
364 views[i].onRowFocus(rowIdx, false);
370 rowIdx = store.indexOf(newFocused);
372 for (i = 0; i < viewsLn; i++) {
373 views[i].onRowFocus(rowIdx, true, supressFocus);
379 onEditorTab: function(editingPlugin, e) {
382 record = editingPlugin.getActiveRecord(),
383 header = editingPlugin.getActiveColumn(),
384 position = view.getPosition(record, header),
385 direction = e.shiftKey ? 'left' : 'right',
386 newPosition = view.walkCells(position, direction, e, this.preventWrap);
389 editingPlugin.startEditByPosition(newPosition);
393 selectByPosition: function(position) {
394 var record = this.store.getAt(position.row);
397 });</pre></pre></body></html>