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
20 Ext.define('Ext.selection.CellModel', {
21 extend: 'Ext.selection.Model',
22 alias: 'selection.cellmodel',
23 requires: ['Ext.util.KeyNav'],
26 * @cfg {Boolean} enableKeyNav
27 * Turns on/off keyboard navigation within the grid. Defaults to true.
32 * @cfg {Boolean} preventWrap
33 * Set this configuration to true to prevent wrapping around of selection as
34 * a user navigates to the first or last column. Defaults to false.
38 constructor: function(){
42 * Fired after a cell is deselected
43 * @param {Ext.selection.CellModel} this
44 * @param {Ext.data.Model} record The record of the deselected cell
45 * @param {Number} row The row index deselected
46 * @param {Number} column The column index deselected
52 * Fired after a cell is selected
53 * @param {Ext.selection.CellModel} this
54 * @param {Ext.data.Model} record The record of the selected cell
55 * @param {Number} row The row index selected
56 * @param {Number} column The column index selected
60 this.callParent(arguments);
63 bindComponent: function(view) {
65 me.primaryView = view;
66 me.views = me.views || [];
68 me.bind(view.getStore(), true);
71 cellmousedown: me.onMouseDown,
72 refresh: me.onViewRefresh,
76 if (me.enableKeyNav) {
81 initKeyNav: function(view) {
85 view.on('render', Ext.Function.bind(me.initKeyNav, me, [view], 0), me, {single: true});
93 // view.el has tabIndex -1 to allow for
94 // keyboard events to be passed to it.
95 me.keyNav = Ext.create('Ext.util.KeyNav', view.el, {
105 getHeaderCt: function() {
106 return this.primaryView.headerCt;
109 onKeyUp: function(e, t) {
113 onKeyDown: function(e, t) {
114 this.move('down', e);
117 onKeyLeft: function(e, t) {
118 this.move('left', e);
121 onKeyRight: function(e, t) {
122 this.move('right', e);
125 move: function(dir, e) {
127 pos = me.primaryView.walkCells(me.getCurrentPosition(), dir, e, me.preventWrap);
129 me.setCurrentPosition(pos);
135 * Returns the current position in the format {row: row, column: column}
137 getCurrentPosition: function() {
138 return this.position;
142 * Sets the current position
143 * @param {Object} position The position to set.
145 setCurrentPosition: function(pos) {
149 me.onCellDeselect(me.position);
152 me.onCellSelect(pos);
158 * Set the current position based on where the user clicks.
161 onMouseDown: function(view, cell, cellIndex, record, row, rowIndex, e) {
162 this.setCurrentPosition({
168 // notify the view that the cell has been selected to update the ui
169 // appropriately and bring the cell into focus
170 onCellSelect: function(position) {
172 store = me.view.getStore(),
173 record = store.getAt(position.row);
176 me.primaryView.onCellSelect(position);
177 // TODO: Remove temporary cellFocus call here.
178 me.primaryView.onCellFocus(position);
179 me.fireEvent('select', me, record, position.row, position.column);
182 // notify view that the cell has been deselected to update the ui
184 onCellDeselect: function(position) {
186 store = me.view.getStore(),
187 record = store.getAt(position.row);
189 me.doDeselect(record);
190 me.primaryView.onCellDeselect(position);
191 me.fireEvent('deselect', me, record, position.row, position.column);
194 onKeyTab: function(e, t) {
196 direction = e.shiftKey ? 'left' : 'right',
197 editingPlugin = me.view.editingPlugin,
198 position = me.move(direction, e);
200 if (editingPlugin && position && me.wasEditing) {
201 editingPlugin.startEditByPosition(position);
203 delete me.wasEditing;
206 onEditorTab: function(editingPlugin, e) {
208 direction = e.shiftKey ? 'left' : 'right',
209 position = me.move(direction, e);
212 editingPlugin.startEditByPosition(position);
213 me.wasEditing = true;
217 refresh: function() {
218 var pos = this.getCurrentPosition();
220 this.onCellSelect(pos);
224 onViewRefresh: function() {
225 var pos = this.getCurrentPosition();
227 this.onCellDeselect(pos);
228 this.setCurrentPosition(null);
232 selectByPosition: function(position) {
233 this.setCurrentPosition(position);