2 * @class Ext.selection.CellModel
3 * @extends Ext.selection.Model
6 Ext.define('Ext.selection.CellModel', {
7 extend: 'Ext.selection.Model',
8 alias: 'selection.cellmodel',
9 requires: ['Ext.util.KeyNav'],
12 * @cfg {Boolean} enableKeyNav
13 * Turns on/off keyboard navigation within the grid. Defaults to true.
18 * @cfg {Boolean} preventWrap
19 * Set this configuration to true to prevent wrapping around of selection as
20 * a user navigates to the first or last column. Defaults to false.
24 constructor: function(){
28 * Fired after a cell is deselected
29 * @param {Ext.selection.CellModel} this
30 * @param {Ext.data.Model} record The record of the deselected cell
31 * @param {Number} row The row index deselected
32 * @param {Number} column The column index deselected
38 * Fired after a cell is selected
39 * @param {Ext.selection.CellModel} this
40 * @param {Ext.data.Model} record The record of the selected cell
41 * @param {Number} row The row index selected
42 * @param {Number} column The column index selected
46 this.callParent(arguments);
49 bindComponent: function(view) {
51 me.primaryView = view;
52 me.views = me.views || [];
54 me.bind(view.getStore(), true);
57 cellmousedown: me.onMouseDown,
58 refresh: me.onViewRefresh,
62 if (me.enableKeyNav) {
67 initKeyNav: function(view) {
71 view.on('render', Ext.Function.bind(me.initKeyNav, me, [view], 0), me, {single: true});
79 // view.el has tabIndex -1 to allow for
80 // keyboard events to be passed to it.
81 me.keyNav = Ext.create('Ext.util.KeyNav', view.el, {
91 getHeaderCt: function() {
92 return this.primaryView.headerCt;
95 onKeyUp: function(e, t) {
99 onKeyDown: function(e, t) {
100 this.move('down', e);
103 onKeyLeft: function(e, t) {
104 this.move('left', e);
107 onKeyRight: function(e, t) {
108 this.move('right', e);
111 move: function(dir, e) {
113 pos = me.primaryView.walkCells(me.getCurrentPosition(), dir, e, me.preventWrap);
115 me.setCurrentPosition(pos);
121 * Returns the current position in the format {row: row, column: column}
123 getCurrentPosition: function() {
124 return this.position;
128 * Sets the current position
129 * @param {Object} position The position to set.
131 setCurrentPosition: function(pos) {
135 me.onCellDeselect(me.position);
138 me.onCellSelect(pos);
144 * Set the current position based on where the user clicks.
147 onMouseDown: function(view, cell, cellIndex, record, row, rowIndex, e) {
148 this.setCurrentPosition({
154 // notify the view that the cell has been selected to update the ui
155 // appropriately and bring the cell into focus
156 onCellSelect: function(position) {
158 store = me.view.getStore(),
159 record = store.getAt(position.row);
162 me.primaryView.onCellSelect(position);
163 // TODO: Remove temporary cellFocus call here.
164 me.primaryView.onCellFocus(position);
165 me.fireEvent('select', me, record, position.row, position.column);
168 // notify view that the cell has been deselected to update the ui
170 onCellDeselect: function(position) {
172 store = me.view.getStore(),
173 record = store.getAt(position.row);
175 me.doDeselect(record);
176 me.primaryView.onCellDeselect(position);
177 me.fireEvent('deselect', me, record, position.row, position.column);
180 onKeyTab: function(e, t) {
182 direction = e.shiftKey ? 'left' : 'right',
183 editingPlugin = me.view.editingPlugin,
184 position = me.move(direction, e);
186 if (editingPlugin && position && me.wasEditing) {
187 editingPlugin.startEditByPosition(position);
189 delete me.wasEditing;
192 onEditorTab: function(editingPlugin, e) {
194 direction = e.shiftKey ? 'left' : 'right',
195 position = me.move(direction, e);
198 editingPlugin.startEditByPosition(position);
199 me.wasEditing = true;
203 refresh: function() {
204 var pos = this.getCurrentPosition();
206 this.onCellSelect(pos);
210 onViewRefresh: function() {
211 var pos = this.getCurrentPosition();
213 this.onCellDeselect(pos);
214 this.setCurrentPosition(null);
218 selectByPosition: function(position) {
219 this.setCurrentPosition(position);