4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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-CellModel'>/**
19 </span> * @class Ext.selection.CellModel
20 * @extends Ext.selection.Model
22 Ext.define('Ext.selection.CellModel', {
23 extend: 'Ext.selection.Model',
24 alias: 'selection.cellmodel',
25 requires: ['Ext.util.KeyNav'],
27 <span id='Ext-selection-CellModel-cfg-enableKeyNav'> /**
28 </span> * @cfg {Boolean} enableKeyNav
29 * Turns on/off keyboard navigation within the grid.
33 <span id='Ext-selection-CellModel-cfg-preventWrap'> /**
34 </span> * @cfg {Boolean} preventWrap
35 * Set this configuration to true to prevent wrapping around of selection as
36 * a user navigates to the first or last column.
40 constructor: function(){
42 <span id='Ext-selection-CellModel-event-deselect'> /**
43 </span> * @event deselect
44 * Fired after a cell is deselected
45 * @param {Ext.selection.CellModel} this
46 * @param {Ext.data.Model} record The record of the deselected cell
47 * @param {Number} row The row index deselected
48 * @param {Number} column The column index deselected
52 <span id='Ext-selection-CellModel-event-select'> /**
53 </span> * @event select
54 * Fired after a cell is selected
55 * @param {Ext.selection.CellModel} this
56 * @param {Ext.data.Model} record The record of the selected cell
57 * @param {Number} row The row index selected
58 * @param {Number} column The column index selected
62 this.callParent(arguments);
65 bindComponent: function(view) {
67 me.primaryView = view;
68 me.views = me.views || [];
70 me.bind(view.getStore(), true);
73 cellmousedown: me.onMouseDown,
74 refresh: me.onViewRefresh,
78 if (me.enableKeyNav) {
83 initKeyNav: function(view) {
87 view.on('render', Ext.Function.bind(me.initKeyNav, me, [view], 0), me, {single: true});
95 // view.el has tabIndex -1 to allow for
96 // keyboard events to be passed to it.
97 me.keyNav = Ext.create('Ext.util.KeyNav', view.el, {
100 right: me.onKeyRight,
107 getHeaderCt: function() {
108 return this.primaryView.headerCt;
111 onKeyUp: function(e, t) {
115 onKeyDown: function(e, t) {
116 this.move('down', e);
119 onKeyLeft: function(e, t) {
120 this.move('left', e);
123 onKeyRight: function(e, t) {
124 this.move('right', e);
127 move: function(dir, e) {
129 pos = me.primaryView.walkCells(me.getCurrentPosition(), dir, e, me.preventWrap);
131 me.setCurrentPosition(pos);
136 <span id='Ext-selection-CellModel-method-getCurrentPosition'> /**
137 </span> * Returns the current position in the format {row: row, column: column}
139 getCurrentPosition: function() {
140 return this.position;
143 <span id='Ext-selection-CellModel-method-setCurrentPosition'> /**
144 </span> * Sets the current position
145 * @param {Object} position The position to set.
147 setCurrentPosition: function(pos) {
151 me.onCellDeselect(me.position);
154 me.onCellSelect(pos);
159 <span id='Ext-selection-CellModel-method-onMouseDown'> /**
160 </span> * Set the current position based on where the user clicks.
163 onMouseDown: function(view, cell, cellIndex, record, row, rowIndex, e) {
164 this.setCurrentPosition({
170 // notify the view that the cell has been selected to update the ui
171 // appropriately and bring the cell into focus
172 onCellSelect: function(position) {
174 store = me.view.getStore(),
175 record = store.getAt(position.row);
178 me.primaryView.onCellSelect(position);
179 // TODO: Remove temporary cellFocus call here.
180 me.primaryView.onCellFocus(position);
181 me.fireEvent('select', me, record, position.row, position.column);
184 // notify view that the cell has been deselected to update the ui
186 onCellDeselect: function(position) {
188 store = me.view.getStore(),
189 record = store.getAt(position.row);
191 me.doDeselect(record);
192 me.primaryView.onCellDeselect(position);
193 me.fireEvent('deselect', me, record, position.row, position.column);
196 onKeyTab: function(e, t) {
198 direction = e.shiftKey ? 'left' : 'right',
199 editingPlugin = me.view.editingPlugin,
200 position = me.move(direction, e);
202 if (editingPlugin && position && me.wasEditing) {
203 editingPlugin.startEditByPosition(position);
205 delete me.wasEditing;
208 onEditorTab: function(editingPlugin, e) {
210 direction = e.shiftKey ? 'left' : 'right',
211 position = me.move(direction, e);
214 editingPlugin.startEditByPosition(position);
215 me.wasEditing = true;
219 refresh: function() {
220 var pos = this.getCurrentPosition();
222 this.onCellSelect(pos);
226 onViewRefresh: function() {
227 var pos = this.getCurrentPosition();
229 this.onCellDeselect(pos);
230 this.setCurrentPosition(null);
234 selectByPosition: function(position) {
235 this.setCurrentPosition(position);