📄 dhtmlxgrid.js
字号:
this.changePage(this.currentPage+1)
}
}
this.selectCell(this.getRowIndex(this.row.idd)+this.rowsBufferOutSize*(ev.keyCode!=33?1:-1),this.cell._cellIndex,true);
/*if(ev.keyCode==33)
this.doDynScroll("up")
else
this.doDynScroll("dn")*/
_isIE?ev.returnValue=false:ev.preventDefault();
}
//RIGHT LEFT
if (!this.editor)
{
if(ev.keyCode==37 && this.cellType._dhx_find("tree")!=-1){
this.collapseKids(this.row)
_isIE?ev.returnValue=false:ev.preventDefault();
}
if(ev.keyCode==39 && this.cellType._dhx_find("tree")!=-1){
this.expandKids(this.row)
_isIE?ev.returnValue=false:ev.preventDefault();
}
}
return true;
} catch(er){ return true; }
}
/**
* @desc: selects row (?)for comtatibility with previous version
* @param: cell - cell object(or cell's child)
* @invoke: click on cell(or cell content)
* @type: private
* @topic: 1,2
*/
this.getRow = function(cell){
if(!cell)
cell = window.event.srcElement;
if(cell.tagName!='TD')
cell = cell.parentElement;
r = cell.parentElement;
if(this.cellType[cell._cellIndex]=='lk')
eval(this.onLink+"('"+this.getRowId(r.rowIndex)+"',"+cell._cellIndex+")");
this.selectCell(r,cell._cellIndex,true)
}
/**
* @desc: selects row (and first cell of it)
* @param: r - row index or row object
* @param: fl - if true, then call function on select
* @param: preserve - preserve previously selected rows true/false (false by default)
* @type: public
* @topic: 1,2
*/
this.selectRow = function(r,fl,preserve){
if(typeof(r)!='object')
r = this.rowsCol[r]
this.selectCell(r,0,fl,preserve)
};
/**
* @desc: sorts specified column
* @param: col - column index
* @param: type - str.int.date
* @param: order - asc.desc
* @type: public
* @topic: 2,3,5,9
*/
this.sortRows = function(col,type,order){
while(this.addRowsFromBuffer(true));//nb:paging - before sorting put all rows from buffer to rows collection.
//if tree cell exists
if(this.cellType._dhx_find("tree")!=-1){
return this.sortTreeRows(col,type,order)
}
var self=this;
var arrTS=new Array();
var atype = this.cellType[col];
for (var i=0; i<this.rowsCol.length; i++)
arrTS[this.rowsCol[i].idd]=this.cells3(this.rowsCol[i],col).getValue();
this._sortRows(col,type,order,arrTS);
}
/**
* @desc: inner sorting routine
* @type: private
* @topic: 7
*/
this._sortRows = function(col,type,order,arrTS){
var sort="sort";
if (this._sst) sort="stablesort";
if(type=='str'){
this.rowsCol[sort](function(a,b){
if(order=="asc")
return arrTS[a.idd]>arrTS[b.idd]?1:-1
else
return arrTS[a.idd]<arrTS[b.idd]?1:-1
});
}else if(type=='int'){
this.rowsCol[sort](function(a,b){
var aVal = parseFloat(arrTS[a.idd])||-99999999999999
var bVal = parseFloat(arrTS[b.idd])||-99999999999999
if(order=="asc")
return aVal-bVal
else
return bVal-aVal
});
}else if(type=='date'){
this.rowsCol[sort](function(a,b){
var aVal = Date.parse(new Date(arrTS[a.idd])||new Date("01/01/1900"))
var bVal = Date.parse(new Date(arrTS[b.idd])||new Date("01/01/1900"))
if(order=="asc")
return aVal-bVal
else
return bVal-aVal
});
}
if(this.dynScroll && this.dynScroll!='false'){
alert("not implemented yet")
}else if(this.pagingOn){//nb:paging
this.changePage(this.currentPage);
if (this.onGridReconstructed) this.onGridReconstructed();
}else{
var tb = this.obj.firstChild;
if (tb.tagName == 'TR') tb = this.obj;
for(var i=0;i<this.rowsCol.length;i++){
if (this.rowsCol[i]!=this.obj._rows(i))
tb.insertBefore(this.rowsCol[i],this.obj._rows(i))
//tb.moveRow(this.rowsCol[i].rowIndex,i)
}
}
//this.setSizes()
if (this.onGridReconstructed) this.onGridReconstructed();
}
/**
* @desc: enables the possibility to load content from server when already loaded content was rendered. Using this you decrease the grid loading time for extremely big amounts of data.
* @type: public
* @topic: 0,7
*/
this.setXMLAutoLoading = function(filePath,bufferSize){
if (arguments.length==0) return (this._xmlaR=true);
this.recordsNoMore = false;
this.xmlFileUrl = filePath;
this.rowsBufferOutSize = bufferSize||this.rowsBufferOutSize==0?40:this.rowsBufferOutSize;
}
/**
* @desc: enables buffering in content rendering. Using this you decrease the grid loading time.
* @type: public
* @topic: 0,7
*/
this.enableBuffering = function(bufferSize){
this.rowsBufferOutSize = bufferSize||this.rowsBufferOutSize==0?40:this.rowsBufferOutSize;;
}
/**
* @desc: create rows from another part of buffer
* @type: private
* @topic: 0,2,7
*/
this.addRowsFromBuffer = function(stopBeforeServerCall){
if(this.rowsBuffer[0].length==0){
if(!this.recordsNoMore && !stopBeforeServerCall){
if ((this.xmlFileUrl!="")&&(!this._startXMLLoading)){
this._startXMLLoading=true;
this.loadXML(this.xmlFileUrl)
}
}else
return false;
}
var cnt = Math.min(this.rowsBufferOutSize,this.rowsBuffer[0].length)
//this.rowsBuffer.length
for(var i=0;i<cnt;i++){
//nb:newbuffer
if(this.rowsBuffer[1][0].tagName == "TR"){//insert already created row
this._insertRowAt(this.rowsBuffer[1][0],-1,this.pagingOn);
}else{//create row from xml tag and insert it
var rowNode = this.rowsBuffer[1][0]
this._insertRowAt(this.createRowFromXMLTag(rowNode),-1,this.pagingOn);
}
this.rowsBuffer[0]._dhx_removeAt(0);
this.rowsBuffer[1]._dhx_removeAt(0);
}
return this.rowsBuffer[0].length!=0;
}
/**
* @desc: creates row object based on xml tag
* @param: rowNode - object of xml tag "row"
* @returns: TR object
*/
this.createRowFromXMLTag = function(rowNode){
if(rowNode.tagName=="TR")//not xml tag, but already created TR
return rowNode;
var tree=this.cellType._dhx_find("tree");
var rId = rowNode.getAttribute("id")
var r= this._fillRowFromXML(this._prepareRow(rId),rowNode,tree,null);
this.rowsAr[rId] = r;
return r;
}
/**
* @desc: allow multiselection
* @param: fl - false/true
* @type: public
* @before_init: 1
* @topic: 0,2,7
*/
this.setMultiselect = function(fl){
this.selMultiRows = convertStringToBoolean(fl);
}
/**
* @desc: called when row was double clicked
* @type: private
* @topic: 1,2
*/
this.wasDblClicked = function(ev){
var el = this.getFirstParentOfType(_isIE?ev.srcElement:ev.target,"TD");
if(el){
var rowId = el.parentNode.idd;
return ((this.onRowDblClicked)?this.onRowDblClicked(rowId,el._cellIndex):true);
}
}
/**
* @desc: called when header was clicked
* @type: private
* @topic: 1,2
*/
this._onHeaderClick = function(e){
var that=this.grid;
var el = that.getFirstParentOfType(_isIE?event.srcElement:e.target,"TD");
if ((this.grid.onHeaderClick)&&(!this.grid.onHeaderClick(el._cellIndexS))) return false;
if (this.grid.resized==null)
that.sortField(el._cellIndexS)
}
/**
* @desc: deletes selected row(s)
* @type: public
* @topic: 2
*/
this.deleteSelectedItem = function(){
var num = this.selectedRows.length//this.obj.rows.length
if(num==0)
return;
var tmpAr = this.selectedRows;
this.selectedRows = new dhtmlxArray(0)
for(var i=num-1;i>=0;i--){
var node = tmpAr[i]
if(!this.deleteRow(node.idd,node)){
this.selectedRows[this.selectedRows.length] = node;
}else{
if(node==this.row){
var ind = i;
}
}
/*
this.rowsAr[node.idd] = null;
var posInCol = this.rowsCol._dhx_find(node)
this.rowsCol[posInCol].parentNode.removeChild(this.rowsCol[posInCol]);//nb:this.rowsCol[posInCol].removeNode(true);
this.rowsCol._dhx_removeAt(posInCol)*/
}
if(ind){
try{
if(ind+1>this.rowsCol.length)//this.obj.rows.length)
ind--;
this.selectCell(ind,0,true)
}catch(er){
this.row = null
this.cell = null
}
}
}
/**
* @desc: gets selected row id
* @returns: id of selected row (list of ids with default delimiter) or null if non row selected
* @type: public
* @topic: 1,2,9
*/
this.getSelectedId = function(){
var selAr = new Array(0);
for(var i=0;i<this.selectedRows.length;i++){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -