3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.selection.CellModel
17 * @extends Ext.selection.Model
19 Ext.define('Ext.selection.CellModel', {
20 extend: 'Ext.selection.Model',
21 alias: 'selection.cellmodel',
22 requires: ['Ext.util.KeyNav'],
25 * @cfg {Boolean} enableKeyNav
26 * Turns on/off keyboard navigation within the grid.
31 * @cfg {Boolean} preventWrap
32 * Set this configuration to true to prevent wrapping around of selection as
33 * a user navigates to the first or last column.
37 constructor: function(){
41 * Fired after a cell is deselected
42 * @param {Ext.selection.CellModel} this
43 * @param {Ext.data.Model} record The record of the deselected cell
44 * @param {Number} row The row index deselected
45 * @param {Number} column The column index deselected
51 * Fired after a cell is selected
52 * @param {Ext.selection.CellModel} this
53 * @param {Ext.data.Model} record The record of the selected cell
54 * @param {Number} row The row index selected
55 * @param {Number} column The column index selected
59 this.callParent(arguments);
62 bindComponent: function(view) {
64 me.primaryView = view;
65 me.views = me.views || [];
67 me.bind(view.getStore(), true);
70 cellmousedown: me.onMouseDown,
71 refresh: me.onViewRefresh,
75 if (me.enableKeyNav) {
80 initKeyNav: function(view) {
84 view.on('render', Ext.Function.bind(me.initKeyNav, me, [view], 0), me, {single: true});
92 // view.el has tabIndex -1 to allow for
93 // keyboard events to be passed to it.
94 me.keyNav = Ext.create('Ext.util.KeyNav', view.el, {
104 getHeaderCt: function() {
105 return this.primaryView.headerCt;
108 onKeyUp: function(e, t) {
112 onKeyDown: function(e, t) {
113 this.move('down', e);
116 onKeyLeft: function(e, t) {
117 this.move('left', e);
120 onKeyRight: function(e, t) {
121 this.move('right', e);
124 move: function(dir, e) {
126 pos = me.primaryView.walkCells(me.getCurrentPosition(), dir, e, me.preventWrap);
128 me.setCurrentPosition(pos);
134 * Returns the current position in the format {row: row, column: column}
136 getCurrentPosition: function() {
137 return this.position;
141 * Sets the current position
142 * @param {Object} position The position to set.
144 setCurrentPosition: function(pos) {
148 me.onCellDeselect(me.position);
151 me.onCellSelect(pos);
157 * Set the current position based on where the user clicks.
160 onMouseDown: function(view, cell, cellIndex, record, row, rowIndex, e) {
161 this.setCurrentPosition({
167 // notify the view that the cell has been selected to update the ui
168 // appropriately and bring the cell into focus
169 onCellSelect: function(position) {
171 store = me.view.getStore(),
172 record = store.getAt(position.row);
175 me.primaryView.onCellSelect(position);
176 // TODO: Remove temporary cellFocus call here.
177 me.primaryView.onCellFocus(position);
178 me.fireEvent('select', me, record, position.row, position.column);
181 // notify view that the cell has been deselected to update the ui
183 onCellDeselect: function(position) {
185 store = me.view.getStore(),
186 record = store.getAt(position.row);
188 me.doDeselect(record);
189 me.primaryView.onCellDeselect(position);
190 me.fireEvent('deselect', me, record, position.row, position.column);
193 onKeyTab: function(e, t) {
195 direction = e.shiftKey ? 'left' : 'right',
196 editingPlugin = me.view.editingPlugin,
197 position = me.move(direction, e);
199 if (editingPlugin && position && me.wasEditing) {
200 editingPlugin.startEditByPosition(position);
202 delete me.wasEditing;
205 onEditorTab: function(editingPlugin, e) {
207 direction = e.shiftKey ? 'left' : 'right',
208 position = me.move(direction, e);
211 editingPlugin.startEditByPosition(position);
212 me.wasEditing = true;
216 refresh: function() {
217 var pos = this.getCurrentPosition();
219 this.onCellSelect(pos);
223 onViewRefresh: function() {
224 var pos = this.getCurrentPosition();
226 this.onCellDeselect(pos);
227 this.setCurrentPosition(null);
231 selectByPosition: function(position) {
232 this.setCurrentPosition(position);