220 lines
No EOL
8 KiB
HTML
220 lines
No EOL
8 KiB
HTML
<html><head><title>CellSelectionModel.js</title><link rel="stylesheet" type="text/css" href="../resources/style.css" media="screen"/></head><body><h1>CellSelectionModel.js</h1><pre class="highlighted"><code><i>/**
|
|
@class Ext.grid.CellSelectionModel
|
|
* @extends Ext.grid.AbstractSelectionModel
|
|
@constructor
|
|
* @param {Object} config
|
|
*/</i>
|
|
Ext.grid.CellSelectionModel = <b>function</b>(config){
|
|
Ext.apply(<b>this</b>, config);
|
|
|
|
<b>this</b>.selection = null;
|
|
|
|
<b>this</b>.addEvents({
|
|
<i>/**
|
|
* @event beforerowselect
|
|
* Fires before a cell is selected.
|
|
* @param {SelectionModel} <b>this</b>
|
|
* @param {Number} rowIndex The selected row index
|
|
* @param {Number} colIndex The selected cell index
|
|
*/</i>
|
|
"beforecellselect" : true,
|
|
<i>/**
|
|
* @event cellselect
|
|
* Fires when a cell is selected.
|
|
* @param {SelectionModel} <b>this</b>
|
|
* @param {Number} rowIndex The selected row index
|
|
* @param {Number} colIndex The selected cell index
|
|
*/</i>
|
|
"cellselect" : true,
|
|
<i>/**
|
|
* @event selectionchange
|
|
* Fires when the active selection changes.
|
|
* @param {SelectionModel} <b>this</b>
|
|
* @param {Object} selection null <b>for</b> no selection or an object (o) <b>with</b> two properties
|
|
<ul>
|
|
<li>o.record: the record object <b>for</b> the row the selection is <b>in</b></li>
|
|
<li>o.cell: An array of [rowIndex, columnIndex]</li>
|
|
</ul>
|
|
*/</i>
|
|
"selectionchange" : true
|
|
});
|
|
};
|
|
|
|
Ext.extend(Ext.grid.CellSelectionModel, Ext.grid.AbstractSelectionModel, {
|
|
|
|
<i>/** @ignore */</i>
|
|
initEvents : <b>function</b>(){
|
|
<b>this</b>.grid.on("mousedown", <b>this</b>.handleMouseDown, <b>this</b>);
|
|
<b>this</b>.grid.container.on(Ext.isIE ? "keydown" : "keypress", <b>this</b>.handleKeyDown, <b>this</b>);
|
|
<b>var</b> view = <b>this</b>.grid.view;
|
|
view.on("refresh", <b>this</b>.onViewChange, <b>this</b>);
|
|
view.on("rowupdated", <b>this</b>.onRowUpdated, <b>this</b>);
|
|
view.on("beforerowremoved", <b>this</b>.clearSelections, <b>this</b>);
|
|
view.on("beforerowsinserted", <b>this</b>.clearSelections, <b>this</b>);
|
|
<b>if</b>(this.grid.isEditor){
|
|
<b>this</b>.grid.on("beforeedit", <b>this</b>.beforeEdit, <b>this</b>);
|
|
}
|
|
},
|
|
|
|
beforeEdit : <b>function</b>(e){
|
|
<b>this</b>.select(e.row, e.column, false, true, e.record);
|
|
},
|
|
|
|
onRowUpdated : <b>function</b>(v, index, r){
|
|
<b>if</b>(this.selection && <b>this</b>.selection.record == r){
|
|
v.onCellSelect(index, <b>this</b>.selection.cell[1]);
|
|
}
|
|
},
|
|
|
|
onViewChange : <b>function</b>(){
|
|
<b>this</b>.clearSelections(true);
|
|
},
|
|
|
|
getSelectedCell : <b>function</b>(){
|
|
<b>return</b> this.selection ? <b>this</b>.selection.cell : null;
|
|
},
|
|
|
|
<i>/**
|
|
* Clears all selections.
|
|
*/</i>
|
|
clearSelections : <b>function</b>(preventNotify){
|
|
<b>var</b> s = <b>this</b>.selection;
|
|
<b>if</b>(s){
|
|
<b>if</b>(preventNotify !== true){
|
|
<b>this</b>.grid.view.onCellDeselect(s.cell[0], s.cell[1]);
|
|
}
|
|
<b>this</b>.selection = null;
|
|
<b>this</b>.fireEvent("selectionchange", <b>this</b>, null);
|
|
}
|
|
},
|
|
|
|
<i>/**
|
|
* Returns True <b>if</b> there is a selection.
|
|
* @<b>return</b> {Boolean}
|
|
*/</i>
|
|
hasSelection : <b>function</b>(){
|
|
<b>return</b> this.selection ? true : false;
|
|
},
|
|
|
|
<i>/** @ignore */</i>
|
|
handleMouseDown : <b>function</b>(e, t){
|
|
<b>var</b> v = <b>this</b>.grid.getView();
|
|
<b>if</b>(this.isLocked()){
|
|
<b>return</b>;
|
|
};
|
|
<b>var</b> row = v.findRowIndex(t);
|
|
<b>var</b> cell = v.findCellIndex(t);
|
|
<b>if</b>(row !== false && cell !== false){
|
|
<b>this</b>.select(row, cell);
|
|
}
|
|
},
|
|
|
|
<i>/**
|
|
* Selects a cell.
|
|
* @param {Number} rowIndex
|
|
* @param {Number} collIndex
|
|
*/</i>
|
|
select : <b>function</b>(rowIndex, colIndex, preventViewNotify, preventFocus, <i>/*internal*/</i> r){
|
|
<b>if</b>(this.fireEvent("beforecellselect", <b>this</b>, rowIndex, colIndex) !== false){
|
|
<b>this</b>.clearSelections();
|
|
r = r || <b>this</b>.grid.dataSource.getAt(rowIndex);
|
|
<b>this</b>.selection = {
|
|
record : r,
|
|
cell : [rowIndex, colIndex]
|
|
};
|
|
<b>if</b>(!preventViewNotify){
|
|
<b>var</b> v = <b>this</b>.grid.getView();
|
|
v.onCellSelect(rowIndex, colIndex);
|
|
<b>if</b>(preventFocus !== true){
|
|
v.focusCell(rowIndex, colIndex);
|
|
}
|
|
}
|
|
<b>this</b>.fireEvent("cellselect", <b>this</b>, rowIndex, colIndex);
|
|
<b>this</b>.fireEvent("selectionchange", <b>this</b>, <b>this</b>.selection);
|
|
}
|
|
},
|
|
|
|
isSelectable : <b>function</b>(rowIndex, colIndex, cm){
|
|
<b>return</b> !cm.isHidden(colIndex);
|
|
},
|
|
|
|
<i>/** @ignore */</i>
|
|
handleKeyDown : <b>function</b>(e){
|
|
<b>if</b>(!e.isNavKeyPress()){
|
|
<b>return</b>;
|
|
}
|
|
<b>var</b> g = <b>this</b>.grid, s = <b>this</b>.selection;
|
|
<b>if</b>(!s){
|
|
e.stopEvent();
|
|
<b>var</b> cell = g.walkCells(0, 0, 1, <b>this</b>.isSelectable, <b>this</b>);
|
|
<b>if</b>(cell){
|
|
<b>this</b>.select(cell[0], cell[1]);
|
|
}
|
|
<b>return</b>;
|
|
}
|
|
<b>var</b> sm = <b>this</b>;
|
|
<b>var</b> walk = <b>function</b>(row, col, step){
|
|
<b>return</b> g.walkCells(row, col, step, sm.isSelectable, sm);
|
|
};
|
|
<b>var</b> k = e.getKey(), r = s.cell[0], c = s.cell[1];
|
|
<b>var</b> newCell;
|
|
|
|
<b>switch</b>(k){
|
|
<b>case</b> e.TAB:
|
|
<b>if</b>(e.shiftKey){
|
|
newCell = walk(r, c-1, -1);
|
|
}<b>else</b>{
|
|
newCell = walk(r, c+1, 1);
|
|
}
|
|
<b>break</b>;
|
|
<b>case</b> e.DOWN:
|
|
newCell = walk(r+1, c, 1);
|
|
<b>break</b>;
|
|
<b>case</b> e.UP:
|
|
newCell = walk(r-1, c, -1);
|
|
<b>break</b>;
|
|
<b>case</b> e.RIGHT:
|
|
newCell = walk(r, c+1, 1);
|
|
<b>break</b>;
|
|
<b>case</b> e.LEFT:
|
|
newCell = walk(r, c-1, -1);
|
|
<b>break</b>;
|
|
<b>case</b> e.ENTER:
|
|
<b>if</b>(g.isEditor && !g.editing){
|
|
g.startEditing(r, c);
|
|
e.stopEvent();
|
|
<b>return</b>;
|
|
}
|
|
<b>break</b>;
|
|
};
|
|
<b>if</b>(newCell){
|
|
<b>this</b>.select(newCell[0], newCell[1]);
|
|
e.stopEvent();
|
|
}
|
|
},
|
|
|
|
acceptsNav : <b>function</b>(row, col, cm){
|
|
<b>return</b> !cm.isHidden(col) && cm.isCellEditable(col, row);
|
|
},
|
|
|
|
onEditorKey : <b>function</b>(field, e){
|
|
<b>var</b> k = e.getKey(), newCell, g = <b>this</b>.grid, ed = g.activeEditor;
|
|
<b>if</b>(k == e.TAB){
|
|
<b>if</b>(e.shiftKey){
|
|
newCell = g.walkCells(ed.row, ed.col-1, -1, <b>this</b>.acceptsNav, <b>this</b>);
|
|
}<b>else</b>{
|
|
newCell = g.walkCells(ed.row, ed.col+1, 1, <b>this</b>.acceptsNav, <b>this</b>);
|
|
}
|
|
e.stopEvent();
|
|
}<b>else</b> if(k == e.ENTER && !e.ctrlKey){
|
|
ed.completeEdit();
|
|
e.stopEvent();
|
|
}<b>else</b> if(k == e.ESC){
|
|
ed.cancelEdit();
|
|
}
|
|
<b>if</b>(newCell){
|
|
g.startEditing(newCell[0], newCell[1]);
|
|
}
|
|
}
|
|
});</code></pre><hr><div style="font-size:10px;text-align:center;color:gray;">Ext - Copyright © 2006-2007 Ext JS, LLC<br />All rights reserved.</div>
|
|
</body></html> |