-<!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-selection.RowModel'>/**
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>The source code</title>
+ <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
+ <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
+ <style type="text/css">
+ .highlight { display: block; background-color: #ddd; }
+ </style>
+ <script type="text/javascript">
+ function highlight() {
+ document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
+ }
+ </script>
+</head>
+<body onload="prettyPrint(); highlight();">
+ <pre class="prettyprint lang-js"><span id='Ext-selection-RowModel'>/**
</span> * @class Ext.selection.RowModel
* @extends Ext.selection.Model
- *
- * Implement row based navigation via keyboard.
- *
- * Must synchronize across grid sections
*/
Ext.define('Ext.selection.RowModel', {
extend: 'Ext.selection.Model',
alias: 'selection.rowmodel',
requires: ['Ext.util.KeyNav'],
-
-<span id='Ext-selection.RowModel-property-deltaScroll'> /**
+
+<span id='Ext-selection-RowModel-property-deltaScroll'> /**
</span> * @private
* Number of pixels to scroll to the left/right when pressing
* left/right keys.
*/
deltaScroll: 5,
-
-<span id='Ext-selection.RowModel-cfg-enableKeyNav'> /**
+
+<span id='Ext-selection-RowModel-cfg-enableKeyNav'> /**
</span> * @cfg {Boolean} enableKeyNav
- *
- * Turns on/off keyboard navigation within the grid. Defaults to true.
+ *
+ * Turns on/off keyboard navigation within the grid.
*/
enableKeyNav: true,
+<span id='Ext-selection-RowModel-cfg-ignoreRightMouseSelection'> /**
+</span> * @cfg {Boolean} [ignoreRightMouseSelection=true]
+ * True to ignore selections that are made when using the right mouse button if there are
+ * records that are already selected. If no records are selected, selection will continue
+ * as normal
+ */
+ ignoreRightMouseSelection: true,
+
constructor: function(){
this.addEvents(
-<span id='Ext-selection.RowModel-event-deselect'> /**
+<span id='Ext-selection-RowModel-event-beforedeselect'> /**
+</span> * @event beforedeselect
+ * Fired before a record is deselected. If any listener returns false, the
+ * deselection is cancelled.
+ * @param {Ext.selection.RowModel} this
+ * @param {Ext.data.Model} record The deselected record
+ * @param {Number} index The row index deselected
+ */
+ 'beforedeselect',
+
+<span id='Ext-selection-RowModel-event-beforeselect'> /**
+</span> * @event beforeselect
+ * Fired before a record is selected. If any listener returns false, the
+ * selection is cancelled.
+ * @param {Ext.selection.RowModel} this
+ * @param {Ext.data.Model} record The selected record
+ * @param {Number} index The row index selected
+ */
+ 'beforeselect',
+
+<span id='Ext-selection-RowModel-event-deselect'> /**
</span> * @event deselect
* Fired after a record is deselected
- * @param {Ext.selection.RowSelectionModel} this
+ * @param {Ext.selection.RowModel} this
* @param {Ext.data.Model} record The deselected record
* @param {Number} index The row index deselected
*/
'deselect',
-
-<span id='Ext-selection.RowModel-event-select'> /**
+
+<span id='Ext-selection-RowModel-event-select'> /**
</span> * @event select
* Fired after a record is selected
- * @param {Ext.selection.RowSelectionModel} this
+ * @param {Ext.selection.RowModel} this
* @param {Ext.data.Model} record The selected record
* @param {Number} index The row index selected
*/
'select'
);
- this.callParent(arguments);
+ this.callParent(arguments);
},
bindComponent: function(view) {
var me = this;
-
+
me.views = me.views || [];
me.views.push(view);
me.bind(view.getStore(), true);
initKeyNav: function(view) {
var me = this;
-
+
if (!view.rendered) {
view.on('render', Ext.Function.bind(me.initKeyNav, me, [view], 0), me, {single: true});
return;
onKeyEnd: function(e, t) {
var me = this,
last = me.store.getAt(me.store.getCount() - 1);
-
+
if (last) {
if (e.shiftKey) {
me.selectRange(last, me.lastFocused || 0);
onKeyHome: function(e, t) {
var me = this,
first = me.store.getAt(0);
-
+
if (first) {
if (e.shiftKey) {
me.selectRange(first, me.lastFocused || 0);
prevIdx,
prevRecord,
currRec;
-
+
if (rowsVisible) {
selIdx = me.lastFocused ? me.store.indexOf(me.lastFocused) : 0;
prevIdx = selIdx - rowsVisible;
nextIdx,
nextRecord,
currRec;
-
+
if (rowsVisible) {
selIdx = me.lastFocused ? me.store.indexOf(me.lastFocused) : 0;
nextIdx = selIdx + rowsVisible;
e.stopEvent();
var me = this,
record = me.lastFocused;
-
+
if (record) {
if (me.isSelected(record)) {
me.doDeselect(record, false);
view = me.views[0],
idx = me.store.indexOf(me.lastFocused),
record;
-
+
if (idx > 0) {
// needs to be the filtered count as thats what
// will be visible.
// There was no lastFocused record, and the user has pressed up
// Ignore??
//else if (this.selected.getCount() == 0) {
- //
+ //
// this.doSelect(record);
// //view.focusRow(idx - 1);
//}
view = me.views[0],
idx = me.store.indexOf(me.lastFocused),
record;
-
+
// needs to be the filtered count as thats what
// will be visible.
if (idx + 1 < me.store.getCount()) {
}
}
},
-
+
scrollByDeltaX: function(delta) {
var view = this.views[0],
section = view.up(),
hScroll = section.horizontalScroller;
-
+
if (hScroll) {
hScroll.scrollByDeltaX(delta);
}
},
-
+
onKeyLeft: function(e, t) {
this.scrollByDeltaX(-this.deltaScroll);
},
-
+
onKeyRight: function(e, t) {
this.scrollByDeltaX(this.deltaScroll);
},
// we can take into account ctrlKey, shiftKey, etc
onRowMouseDown: function(view, record, item, index, e) {
view.el.focus();
+ if (!this.allowRightMouseSelection(e)) {
+ return;
+ }
this.selectWithEvent(record, e);
},
+
+<span id='Ext-selection-RowModel-method-allowRightMouseSelection'> /**
+</span> * Checks whether a selection should proceed based on the ignoreRightMouseSelection
+ * option.
+ * @private
+ * @param {Ext.EventObject} e The event
+ * @return {Boolean} False if the selection should not proceed
+ */
+ allowRightMouseSelection: function(e) {
+ var disallow = this.ignoreRightMouseSelection && e.button !== 0;
+ if (disallow) {
+ disallow = this.hasSelection();
+ }
+ return !disallow;
+ },
// Allow the GridView to update the UI by
// adding/removing a CSS class from the row.
- onSelectChange: function(record, isSelected, suppressEvent) {
+ onSelectChange: function(record, isSelected, suppressEvent, commitFn) {
var me = this,
views = me.views,
viewsLn = views.length,
store = me.store,
rowIdx = store.indexOf(record),
+ eventName = isSelected ? 'select' : 'deselect',
i = 0;
-
- for (; i < viewsLn; i++) {
- if (isSelected) {
- views[i].onRowSelect(rowIdx, suppressEvent);
- if (!suppressEvent) {
- me.fireEvent('select', me, record, rowIdx);
- }
- } else {
- views[i].onRowDeselect(rowIdx, suppressEvent);
- if (!suppressEvent) {
- me.fireEvent('deselect', me, record, rowIdx);
+
+ if ((suppressEvent || me.fireEvent('before' + eventName, me, record, rowIdx)) !== false &&
+ commitFn() !== false) {
+
+ for (; i < viewsLn; i++) {
+ if (isSelected) {
+ views[i].onRowSelect(rowIdx, suppressEvent);
+ } else {
+ views[i].onRowDeselect(rowIdx, suppressEvent);
}
}
+
+ if (!suppressEvent) {
+ me.fireEvent(eventName, me, record, rowIdx);
+ }
}
},
store = this.store,
rowIdx,
i = 0;
-
+
if (oldFocused) {
rowIdx = store.indexOf(oldFocused);
if (rowIdx != -1) {
}
}
},
-
+
onEditorTab: function(editingPlugin, e) {
var me = this,
view = me.views[0],
position = view.getPosition(record, header),
direction = e.shiftKey ? 'left' : 'right',
newPosition = view.walkCells(position, direction, e, this.preventWrap);
-
+
if (newPosition) {
editingPlugin.startEditByPosition(newPosition);
}
},
-
+
selectByPosition: function(position) {
var record = this.store.getAt(position.row);
this.select(record);
}
-});</pre></pre></body></html>
\ No newline at end of file
+});</pre>
+</body>
+</html>