📄 dhtmlxgrid.js
字号:
this.clearSelection();
}else if(selMethod==1){
var elRowIndex = this.rowsCol._dhx_find(el.parentNode)
var lcRowIndex = this.rowsCol._dhx_find(this.lastClicked)
if(elRowIndex>lcRowIndex){
var strt = lcRowIndex;
var end = elRowIndex;
}else{
var strt = elRowIndex;
var end = lcRowIndex;
}
this.clearSelection();
for(var i=0;i<this.rowsCol.length;i++){
if((i>=strt && i<=end)&&(this.rowsCol[i])&&(!this.rowsCol[i]._sRow)){
if ((!this.onBFS)||(this.onBFS(this.rowsCol[i].idd,psid))){
this.rowsCol[i].className+=" rowselected";
this.selectedRows[this.selectedRows.length] = this.rowsCol[i]
}
}/*else{
this.rowsCol[i].className = "";
}*/
}
}else if(selMethod==2){
if(el.parentNode.className.indexOf("rowselected") != -1){
el.parentNode.className=el.parentNode.className.replace("rowselected","");
this.selectedRows._dhx_removeAt(this.selectedRows._dhx_find(el.parentNode))
var skipRowSelection = true;
}
}
this.editStop()
this.cell = el;
if ((prow == el.parentNode)&&(this._chRRS))
fl=false;
this.row = el.parentNode;
if((!skipRowSelection)&&(!this.row._sRow)){
if ((!this.onBFS)||(this.onBFS(this.row.idd,psid))){
this.row.className+= " rowselected"
if(this.selectedRows._dhx_find(this.row)==-1)
this.selectedRows[this.selectedRows.length] = this.row;
}
else this.row=true;
}
if(this.selBasedOn=="cell"){
if (this.cell.parentNode.className.indexOf("rowselected")!=-1)
this.cell.className = this.cell.className.replace(/cellselected/g,"")+" cellselected";
}
if(selMethod!=1)
this.lastClicked = el.parentNode;
var rid = this.row.idd;
var cid = this.cell.cellIndex;
if (fl) setTimeout(function(){ self.onRowSelect(rid,cid); },100)
if (this.onSSC) {
var afinal=this.getSelectedId();
if (initial!=afinal) this.onSSC(afinal);
}
}
this.isActive = true;
this.moveToVisible(this.cell)
}
/**
* @desc: set selection to specified row-cell
* @param: r - row object or row index
* @param: cInd - cell index
* @param: [fl] - true if to call onRowSelect function
* @param: preserve - preserve previously selected rows true/false (false by default)
* @param: edit - switch selected cell to edit mode
* @type: public
* @topic: 1,4
*/
this.selectCell = function(r,cInd,fl,preserve,edit){
if(!fl)
fl = false;
if(typeof(r)!="object")
r = this.rowsCol[r]
var c = r.childNodes[cInd];
if (preserve)
this.doClick(c,fl,3)
else
this.doClick(c,fl)
if (edit) this.editCell();
}
/**
* @desc: moves specified cell to visible area (scrolls)
* @param: cell_obj - object of the cell to work with
* @param: onlyVScroll - allow only vertical positioning
* @type: private
* @topic: 2,4,7
*/
this.moveToVisible = function(cell_obj,onlyVScroll){
try{
var distance = cell_obj.offsetLeft+cell_obj.offsetWidth+20;
if(distance>(this.objBox.offsetWidth+this.objBox.scrollLeft)){
var scrollLeft = distance - this.objBox.offsetWidth;
}else if(cell_obj.offsetLeft<this.objBox.scrollLeft){
var scrollLeft = cell_obj.offsetLeft-5
}
if ((scrollLeft)&&(!onlyVScroll))
this.objBox.scrollLeft = scrollLeft;
var distance = cell_obj.offsetTop+cell_obj.offsetHeight + 20;
if(distance>(this.objBox.offsetHeight+this.objBox.scrollTop)){
var scrollTop = distance - this.objBox.offsetHeight;
}else if(cell_obj.offsetTop<this.objBox.scrollTop){
var scrollTop = cell_obj.offsetTop-5
}
if(scrollTop)
this.objBox.scrollTop = scrollTop;
}catch(er){
}
}
/**
* @desc: creates Editor object and switch cell to edit mode if allowed
* @type: public
* @topic: 4
*/
this.editCell = function(){
this.editStop();
if ((this.isEditable!=true)||(!this.cell))
return false;
var c = this.cell;
//#locked_row:11052006{
if (c.parentNode._locked) return false;
//#}
this.editor = this.cells4(c);
//initialize editor
if(this.editor!=null){
if (this.editor.isDisabled()) { this.editor=null; return false; }
c.className+=" editable";
if(this.onEditCell(0,this.row.idd,this.cell._cellIndex)!=false){
this._Opera_stop=(new Date).valueOf();
this.editor.edit()
this.onEditCell(1,this.row.idd,this.cell._cellIndex)
}else{//preserve editing
this.editor=null;
}
}
}
/**
* @desc: gets value from editor(if presents) to cell and closes editor
* @type: public
* @topic: 4
*/
this.editStop = function(){
if (_isOpera)
if (this._Opera_stop){
if ((this._Opera_stop*1+50)>(new Date).valueOf()) return;
this._Opera_stop=null;
}
if(this.editor && this.editor!=null){
this.cell.className=this.cell.className.replace("editable","");
if (this.editor.detach()) this.cell.wasChanged = true;
var g=this.editor;
this.editor=null;
var z=this.onEditCell(2,this.row.idd,this.cell._cellIndex,g.getValue(),g.val);
if ((typeof(z)=="string")||(typeof(z)=="number"))
g.setValue(z);
else
if (!z) g.setValue(g.val);
}
}
/**
* @desc: manages keybord activity in grid
* @type: private
* @topic: 7
*/
this.doKey = function(ev){
if (!ev) return true;
if ((ev.target||ev.srcElement).value!==window.undefined){
var zx= (ev.target||ev.srcElement);
if ((!zx.parentNode)||(zx.parentNode.className.indexOf("editable")==-1))
return true;
}
if ((globalActiveDHTMLGridObject)&&(this!=globalActiveDHTMLGridObject))
return globalActiveDHTMLGridObject.doKey(ev);
if(this.isActive==false){
//document.body.onkeydown = "";
return true;
}
if (this._htkebl) return true;
if ((this.onKPR)&&(!this.onKPR(ev.keyCode,ev.ctrlKey,ev.shiftKey))) return false;
try{
var type = this.cellType[this.cell._cellIndex]
//ENTER
if(ev.keyCode==13 && (ev.ctrlKey || ev.shiftKey)){
var rowInd = this.rowsCol._dhx_find(this.row)
if(window.event.ctrlKey && rowInd!=this.rowsCol.length-1){
if(this.row.rowIndex==this.obj._rowslength()-1 && this.dynScroll && this.dynScroll!='false')
this.doDynScroll("dn")
this.selectCell(this.rowsCol[rowInd+1],this.cell._cellIndex,true);
}else if(ev.shiftKey && rowInd!=0){
if(this.row.rowIndex==0 && this.dynScroll && this.dynScroll!='false')
this.doDynScroll("up")
this.selectCell(this.rowsCol[rowInd-1],this.cell._cellIndex,true);
}
_isIE?ev.returnValue=false:ev.preventDefault();
}
if(ev.keyCode==13 && !ev.ctrlKey && !ev.shiftKey){
this.editStop();
this.onEnter(this.row.idd,this.cell._cellIndex);
_isIE?ev.returnValue=false:ev.preventDefault();
}
//TAB
if(ev.keyCode==9 && !ev.shiftKey ){
this.editStop();
var aind=this.cell._cellIndex;
var arow=this.row;
aind++;
if (aind>=this.obj.rows[0].childNodes.length){
aind=0;
arow=this.rowsCol[this.rowsCol._dhx_find(this.row)+1];
if (!arow){
aind=this.row.childNodes.length-1;
return true; }
}
this.selectCell(arow||this.row,aind,((arow)&&(this.row!=arow)));
this.editCell()
_isIE?ev.returnValue=false:ev.preventDefault();
}else if(ev.keyCode==9 && ev.shiftKey){
this.editStop();
var aind=this.cell._cellIndex-1;
var arow=this.row;
if (aind<0)
{
aind=this.obj.rows[0].childNodes.length-1;
arow=this.rowsCol[this.rowsCol._dhx_find(this.row)-1];
if (!arow) { aind=0;
return true; }
}
this.selectCell(arow||this.row,aind,((arow)&&(this.row!=arow)));
this.editCell()
_isIE?ev.returnValue=false:ev.preventDefault();
}
//UP & DOWN
if(ev.keyCode==40 || ev.keyCode==38){//&& ev.ctrlKey
if (this.editor && this.editor.combo){
if (ev.keyCode==40) this.editor.shiftNext();
if (ev.keyCode==38) this.editor.shiftPrev();
return false;
}
else{
var rowInd = this.row.rowIndex;//rowsCol._dhx_find(this.row)
if(ev.keyCode==38 && rowInd!=1){
//if(this.row.rowIndex==0 && this.dynScroll && this.dynScroll!='false')
// this.doDynScroll("up")
this.selectCell(this.obj._rows(rowInd-2),this.cell._cellIndex,true);
}else if(this.pagingOn && ev.keyCode==38 && rowInd==1 && this.currentPage!=1){
this.changePage(this.currentPage-1)
this.selectCell(this.obj.rows[this.obj.rows.length-1],this.cell._cellIndex,true);
}else if(ev.keyCode==40 && rowInd!=this.rowsCol.length && rowInd!=this.obj.rows.length-1){
//if(this.row.rowIndex==this.obj._rowslength-1 && this.dynScroll && this.dynScroll!='false')
// this.doDynScroll("dn")
this.selectCell(this.obj._rows(rowInd),this.cell._cellIndex,true);
}else if(this.pagingOn && ev.keyCode==40 && (this.row!=this.rowsCol[this.rowsCol.length-1] || this.rowsBuffer[0].length>0 || !this.recordsNoMore)){
this.changePage(this.currentPage+1)
this.selectCell(this.obj._rows(0),this.cell._cellIndex,true);
}
}
_isIE?ev.returnValue=false:ev.preventDefault();
}
//F2
if((ev.keyCode==113)&&(this._f2kE)){
this.editCell();
return false;
}
//SPACE
if(ev.keyCode==32){// && (type=='ch'|| type.indexOf('ra')==0)){
var c = this.cell
var ed = cells4(c);
//this.cell.children(0).click()
if(ed.changeState()!=false)
_isIE?ev.returnValue=false:ev.preventDefault();
}
//Esc
if(ev.keyCode==27 && this.oe!=false){
this.editStop();
_isIE?ev.returnValue=false:ev.preventDefault();
}
//PAGEUP / PAGEDOWN
if(ev.keyCode==33 || ev.keyCode==34){
if(this.pagingOn){
if(ev.keyCode==33){
this.changePage(this.currentPage-1)
}else{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -