/*!
- * Ext JS Library 3.0.0
- * Copyright(c) 2006-2009 Ext JS, LLC
+ * Ext JS Library 3.2.0
+ * Copyright(c) 2006-2010 Ext JS, Inc.
* licensing@extjs.com
* http://www.extjs.com/license
*/
* @constructor
* @param {Object} config
*/
-Ext.grid.RowSelectionModel = function(config){
- Ext.apply(this, config);
- this.selections = new Ext.util.MixedCollection(false, function(o){
- return o.id;
- });
-
- this.last = false;
- this.lastActive = false;
-
- this.addEvents(
- /**
- * @event selectionchange
- * Fires when the selection changes
- * @param {SelectionModel} this
- */
- "selectionchange",
- /**
- * @event beforerowselect
- * Fires before a row is selected, return false to cancel the selection.
- * @param {SelectionModel} this
- * @param {Number} rowIndex The index to be selected
- * @param {Boolean} keepExisting False if other selections will be cleared
- * @param {Record} record The record to be selected
- */
- "beforerowselect",
- /**
- * @event rowselect
- * Fires when a row is selected.
- * @param {SelectionModel} this
- * @param {Number} rowIndex The selected index
- * @param {Ext.data.Record} r The selected record
- */
- "rowselect",
- /**
- * @event rowdeselect
- * Fires when a row is deselected. To prevent deselection
- * {@link Ext.grid.AbstractSelectionModel#lock lock the selections}.
- * @param {SelectionModel} this
- * @param {Number} rowIndex
- * @param {Record} record
- */
- "rowdeselect"
- );
-
- Ext.grid.RowSelectionModel.superclass.constructor.call(this);
-};
-
-Ext.extend(Ext.grid.RowSelectionModel, Ext.grid.AbstractSelectionModel, {
+Ext.grid.RowSelectionModel = Ext.extend(Ext.grid.AbstractSelectionModel, {
/**
* @cfg {Boolean} singleSelect
* <tt>true</tt> to allow selection of only one row at a time (defaults to <tt>false</tt>
* allowing multiple selections)
*/
singleSelect : false,
+
+ constructor : function(config){
+ Ext.apply(this, config);
+ this.selections = new Ext.util.MixedCollection(false, function(o){
+ return o.id;
+ });
+
+ this.last = false;
+ this.lastActive = false;
+
+ this.addEvents(
+ /**
+ * @event selectionchange
+ * Fires when the selection changes
+ * @param {SelectionModel} this
+ */
+ 'selectionchange',
+ /**
+ * @event beforerowselect
+ * Fires before a row is selected, return false to cancel the selection.
+ * @param {SelectionModel} this
+ * @param {Number} rowIndex The index to be selected
+ * @param {Boolean} keepExisting False if other selections will be cleared
+ * @param {Record} record The record to be selected
+ */
+ 'beforerowselect',
+ /**
+ * @event rowselect
+ * Fires when a row is selected.
+ * @param {SelectionModel} this
+ * @param {Number} rowIndex The selected index
+ * @param {Ext.data.Record} r The selected record
+ */
+ 'rowselect',
+ /**
+ * @event rowdeselect
+ * Fires when a row is deselected. To prevent deselection
+ * {@link Ext.grid.AbstractSelectionModel#lock lock the selections}.
+ * @param {SelectionModel} this
+ * @param {Number} rowIndex
+ * @param {Record} record
+ */
+ 'rowdeselect'
+ );
+ Ext.grid.RowSelectionModel.superclass.constructor.call(this);
+ },
/**
* @cfg {Boolean} moveEditorOnEnter
initEvents : function(){
if(!this.grid.enableDragDrop && !this.grid.enableDrag){
- this.grid.on("rowmousedown", this.handleMouseDown, this);
- }else{ // allow click to work like normal
- this.grid.on("rowclick", function(grid, rowIndex, e) {
- if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
- this.selectRow(rowIndex, false);
- grid.view.focusRow(rowIndex);
- }
- }, this);
+ this.grid.on('rowmousedown', this.handleMouseDown, this);
}
this.rowNav = new Ext.KeyNav(this.grid.getGridEl(), {
- "up" : function(e){
+ 'up' : function(e){
if(!e.shiftKey || this.singleSelect){
this.selectPrevious(false);
}else if(this.last !== false && this.lastActive !== false){
this.selectFirstRow();
}
},
- "down" : function(e){
+ 'down' : function(e){
if(!e.shiftKey || this.singleSelect){
this.selectNext(false);
}else if(this.last !== false && this.lastActive !== false){
scope: this
});
- var view = this.grid.view;
- view.on("refresh", this.onRefresh, this);
- view.on("rowupdated", this.onRowUpdated, this);
- view.on("rowremoved", this.onRemove, this);
+ this.grid.getView().on({
+ scope: this,
+ refresh: this.onRefresh,
+ rowupdated: this.onRowUpdated,
+ rowremoved: this.onRemove
+ });
},
// private
}
}
if(s.length != this.selections.getCount()){
- this.fireEvent("selectionchange", this);
+ this.fireEvent('selectionchange', this);
}
},
* Calls the passed function with each selection. If the function returns
* <tt>false</tt>, iteration is stopped and this function returns
* <tt>false</tt>. Otherwise it returns <tt>true</tt>.
- * @param {Function} fn
- * @param {Object} scope (optional)
+ * @param {Function} fn The function to call upon each iteration. It is passed the selected {@link Ext.data.Record Record}.
+ * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this RowSelectionModel.
* @return {Boolean} true if all selections were iterated
*/
each : function(fn, scope){
* @return {Boolean}
*/
isSelected : function(index){
- var r = typeof index == "number" ? this.grid.store.getAt(index) : index;
+ var r = Ext.isNumber(index) ? this.grid.store.getAt(index) : index;
return (r && this.selections.key(r.id) ? true : false);
},
return;
}
var r = this.grid.store.getAt(index);
- if(r && this.fireEvent("beforerowselect", this, index, keepExisting, r) !== false){
+ if(r && this.fireEvent('beforerowselect', this, index, keepExisting, r) !== false){
if(!keepExisting || this.singleSelect){
this.clearSelections();
}
if(!preventViewNotify){
this.grid.getView().onRowSelect(index);
}
- this.fireEvent("rowselect", this, index, r);
- this.fireEvent("selectionchange", this);
+ this.fireEvent('rowselect', this, index, r);
+ this.fireEvent('selectionchange', this);
}
},
if(!preventViewNotify){
this.grid.getView().onRowDeselect(index);
}
- this.fireEvent("rowdeselect", this, index, r);
- this.fireEvent("selectionchange", this);
+ this.fireEvent('rowdeselect', this, index, r);
+ this.fireEvent('selectionchange', this);
}
},
// private
onEditorKey : function(field, e){
- var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
+ var k = e.getKey(),
+ newCell,
+ g = this.grid,
+ last = g.lastEdit,
+ ed = g.activeEditor,
+ ae, last, r, c;
var shift = e.shiftKey;
if(k == e.TAB){
e.stopEvent();
newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
}
}else if(k == e.ENTER){
- e.stopEvent();
- ed.completeEdit();
if(this.moveEditorOnEnter !== false){
if(shift){
- newCell = g.walkCells(ed.row - 1, ed.col, -1, this.acceptsNav, this);
+ newCell = g.walkCells(last.row - 1, last.col, -1, this.acceptsNav, this);
}else{
- newCell = g.walkCells(ed.row + 1, ed.col, 1, this.acceptsNav, this);
+ newCell = g.walkCells(last.row + 1, last.col, 1, this.acceptsNav, this);
}
}
- }else if(k == e.ESC){
- ed.cancelEdit();
}
if(newCell){
- g.startEditing(newCell[0], newCell[1]);
+ r = newCell[0];
+ c = newCell[1];
+
+ if(last.row != r){
+ this.selectRow(r); // *** highlight newly-selected cell and update selection
+ }
+
+ if(g.isEditor && g.editing){ // *** handle tabbing while editorgrid is in edit mode
+ ae = g.activeEditor;
+ if(ae && ae.field.triggerBlur){
+ // *** if activeEditor is a TriggerField, explicitly call its triggerBlur() method
+ ae.field.triggerBlur();
+ }
+ }
+ g.startEditing(r, c);
}
},
- destroy: function(){
+ destroy : function(){
if(this.rowNav){
this.rowNav.disable();
this.rowNav = null;