📄 zpgrid.js
字号:
oEditor.receiveData({data:aRows});};Zapatec.Grid.prototype.editSelectedCells=function(oEditor){if(!oEditor||!oEditor.receiveData){return;}var aCells=this.getSelectedCells();if(!aCells.length){alert(this.getMessage('errorSelectCell'));return;}oEditor.receiveData({data:aCells});};Zapatec.Grid.prototype.prepareSpans=function(aRows,bOut){var aFields=this.fields;var iFields=aFields.length;var iRows=aRows.length;if(iFields&&iRows){var aRF=[];var fClone=Zapatec.Utils.clone;var iHorizHiddenStart=this.config.fixedLeft;var iHorizHiddenEnd=iHorizHiddenStart+this.currentHorizontalOffset;var iRow,oRow,aCells,iCell,iC,oCell,oRF,oC,iRowspan,iColspan;for(iRow=0;iRows--;iRow++){oRow=aRows[iRow];if(!oRow){continue;}aCells=oRow.cells;if(!aCells){continue;}for(iCell=0;iCell<iFields;iCell++){oCell=aCells[iCell];oRF=aRF[iCell];if(oCell){if(oRF){oC=oRF.cell;if(oC.i==oCell.i&&oC.r==oCell.r){if(bOut){aCells[iCell]=null;oRow.spanned=true;}if(!--oRF.rowspan){aRF[iCell]=null;}else if(!iRows){oC.rowspan-=oRF.rowspan;aRF[iCell]=null;}if(bOut){iColspan=oCell.colspan;if(iColspan>1){for(iCell++;--iColspan;iCell++){aCells[iCell]=null;}continue;}}}else{if(bOut){iRowspan=oC.rowspan-oRF.rowspan;if(iRowspan<2){iRowspan=0;}oC.rowspan=iRowspan;if(oC.r<this.currentVerticalOffset){oC.v='';}iColspan=oC.colspan;if(iColspan>1){var aSpannedCells=oRF.row.cells;var oSpannedCell;for(var iOffset=1;iOffset<iColspan;iOffset++){oSpannedCell=aSpannedCells[iCell+iOffset];if(oSpannedCell){oSpannedCell.rowspan=iRowspan;}}}}aRF[iCell]=null;iCell--;continue;}}else{iRowspan=oCell.rowspan;if(iRowspan>1){if(iRows){aRF[iCell]={rowspan:--iRowspan,row:oRow,cell:oCell};oRow.spanned=true;}else{oCell.rowspan=0;}}}iColspan=oCell.colspan;if(iColspan>1){if(bOut){while(iColspan&&aFields[iCell].hidden){oCell=aCells[++iCell];iColspan--;}while(iColspan&&iCell>=iHorizHiddenStart&&iCell<iHorizHiddenEnd){oCell=aCells[++iCell];oCell.v='';iColspan--;}if(oCell){oCell.colspan=iColspan;}if(iColspan>0){iColspan--;iCell++;while(aFields[iCell]&&iColspan--){if(aFields[iCell].hidden){if(oCell){oCell.colspan--;}}aCells[iCell]=null;iCell++;}iCell--;}}else{for(iCell++;--iColspan;iCell++){oC=fClone(oCell);oC.i=iCell;aCells[iCell]=this.convertCell(oC);}iCell--;}}}else if(oRF){if(bOut){oRow.spanned=true;}else{aCells[iCell]=oRF.cell;if(!--oRF.rowspan){aRF[iCell]=null;}else if(!iRows){oRF.cell.rowspan-=oRF.rowspan;aRF[iCell]=null;}if(!bOut){oCell=aCells[iCell];iColspan=oCell.colspan;if(iColspan>1){for(iCell++;--iColspan;iCell++){oC=fClone(oCell);oC.i=iCell;aCells[iCell]=this.convertCell(oC);}}}}}}}}return aRows;};Zapatec.Grid.onCellMouseup=function(iRow,iCell){var oEvent=window.event;var iButton=oEvent.button||oEvent.which||1;if(iButton==1&&(oEvent.metaKey||(window.opera&&oEvent.altKey))){iButton=2;}if(iButton>1){var oConfig=this.config;if(typeof oConfig.callbackCellOnRightClick=='function'){oConfig.callbackCellOnRightClick(this,this.getCellById(iRow,iCell));}else if(typeof oConfig.callbackRowOnRightClick=='function'){oConfig.callbackRowOnRightClick(this,this.getRowById(iRow));}}};Zapatec.Grid.prototype.moveColumn=function(oArg){if(!oArg){return;}var iColumn=parseInt(oArg.fieldId);if(isNaN(iColumn)){return;}var aFields=this.fields;var iFields=aFields.length;if(!aFields[iColumn]){return;}var iPos=parseInt(oArg.position);if(isNaN(iPos)){return;}if(iPos<0){iPos=0;}else if(!aFields[iPos]){iPos=aFields[iFields-1].i;if(isNaN(iPos)){return;}}if(iColumn==iPos){return false;}var aRemoved;aRemoved=aFields.splice(iColumn,1);aFields.splice(iPos,0,aRemoved[0]);var iStart=iColumn;var iEnd=iPos;var iIncrement=-1;if(iColumn>iPos){iStart=iPos;iEnd=iColumn;iIncrement=1;}var iCol;for(iCol=iStart;iCol<=iEnd;iCol++){aFields[iCol].i=iCol;}var aRules=this.filterOutRules;aRules=aRules.concat(this.totalsRules);var iRules=aRules.length;var iRule,oRule,aCols,iCols,iFieldId;for(iRule=0;iRule<iRules;iRule++){oRule=aRules[iRule];aCols=oRule.column;if(aCols instanceof Array){iCols=aCols.length;for(iCol=0;iCol<iCols;iCol++){iFieldId=aCols[iCol];if(iFieldId==iColumn){aCols[iCol]=iPos;}else if(iFieldId>=iStart&&iFieldId<=iEnd){aCols[iCol]+=iIncrement;}}}else{iFieldId=aCols;if(iFieldId==iColumn){oRule.column=iPos;}else if(iFieldId>=iStart&&iFieldId<=iEnd){oRule.column+=iIncrement;}}}var aRows=this.rows;var iRows=aRows.length;var iRow,oRow,aCells;for(iRow=0;iRow<iRows;iRow++){oRow=aRows[iRow];aCells=oRow.cells;aRemoved=aCells.splice(iColumn,1);aCells.splice(iPos,0,aRemoved[0]);for(iCol=iStart;iCol<=iEnd;iCol++){aCells[iCol].i=iCol;}}this.fireEvent('gridMovedColumn',{fieldId:iColumn,position:iPos});if(!oArg.noRefresh){this.refresh();}return true;};Zapatec.Grid.getNewColumnNumber=function(oArg){if(!oArg){return;}var iFieldId=parseInt(oArg.fieldId);if(isNaN(iFieldId)){return;}var oMove=oArg.move;if(!oMove){return;}var iColumn=parseInt(oMove.fieldId);if(isNaN(iColumn)){return;}var iPos=parseInt(oMove.position);if(isNaN(iPos)){return;}if(iColumn==iPos){return iFieldId;}var iStart=iColumn;var iEnd=iPos;var iIncrement=-1;if(iColumn>iPos){iStart=iPos;iEnd=iColumn;iIncrement=1;}if(iFieldId==iColumn){return iPos;}else if(iFieldId>=iStart&&iFieldId<=iEnd){return iFieldId+iIncrement;}return iFieldId;};Zapatec.Grid.prototype.convertString=function(oCell){if(!(oCell instanceof Object)){oCell={};}oCell.v+='';oCell.v=oCell.v.replace(/\s+/g,' ');oCell.v=oCell.v.replace(/^\s/,'').replace(/\s$/,'');oCell.c=oCell.o=oCell.v;oCell.c=oCell.c.replace(/<[^>]*>/g,'');return oCell;};Zapatec.Grid.prototype.convertInsensitiveString=function(oCell){oCell=this.convertString(oCell);oCell.c=oCell.c.toUpperCase();return oCell;};Zapatec.Grid.prototype.searchInsensitiveString=function(oArg){if(!oArg){return;}var oCell=oArg.cell;var sText=this.getCellValueString(oCell);sText=sText.replace(/<[^>]*>/g,'');return sText.search(new RegExp(Zapatec.Utils.escapeRegExp(oArg.searchValue),'i'));};Zapatec.Grid.prototype.convertInteger=function(oCell){if(oCell&&(oCell.v==Infinity||oCell.v==-Infinity)){return oCell;}oCell=this.convertString(oCell);oCell.c=oCell.c.replace(/[^0-9\.\-]/g,'');oCell.c=oCell.c.replace(/\..*/g,'');oCell.c=parseInt(oCell.c);if(isNaN(oCell.c)){oCell.c=0;}return oCell;};Zapatec.Grid.prototype.convertIntegerGerman=function(oCell){if(oCell&&(oCell.v==Infinity||oCell.v==-Infinity)){return oCell;}oCell=this.convertString(oCell);oCell.c=oCell.c.replace(/[^0-9,\-]/g,'');oCell.c=oCell.c.replace(/,.*/g,'');oCell.c=parseInt(oCell.c);if(isNaN(oCell.c)){oCell.c=0;}return oCell;};Zapatec.Grid.prototype.convertFloat=function(oCell){if(oCell&&(oCell.v==Infinity||oCell.v==-Infinity)){return oCell;}oCell=this.convertString(oCell);oCell.c=oCell.c.replace(/[^0-9\.\-]/g,'');oCell.c=parseFloat(oCell.c);if(isNaN(oCell.c)){oCell.c=0;}return oCell;};Zapatec.Grid.prototype.convertFloatGerman=function(oCell){if(oCell&&(oCell.v==Infinity||oCell.v==-Infinity)){return oCell;}oCell=this.convertString(oCell);oCell.c=oCell.c.replace(/[^0-9,\-]/g,'');oCell.c=oCell.c.replace(/,/g,'.');oCell.c=parseFloat(oCell.c);if(isNaN(oCell.c)){oCell.c=0;}return oCell;};Zapatec.Grid.prototype.convertDate=function(oCell){oCell=this.convertString(oCell);oCell.c=Date.parse(oCell.c);return oCell;};Zapatec.Grid.prototype.convertTime=function(oCell){oCell=this.convertString(oCell);var aMatches=oCell.c.match(/(\d{1,2})\D+(\d{1,2})(\D+(\d{1,2}))?\W*(AM|PM|A|P)?/i);if(!aMatches){aMatches=oCell.c.match(/(\d{2})(\d{2})((\d{2}))?\W*(AM|PM|A|P)?/i);}if(aMatches&&aMatches[1]&&aMatches[2]){var hour=aMatches[1]*1;if(aMatches[5]){var sAmPm=aMatches[5].toUpperCase();if(sAmPm=='PM'||sAmPm=='P'){if(hour<12){hour+=12;}}else{if(hour==12){hour=0;}}}if(hour<10){hour='0'+hour;}var minute=aMatches[2]*1;if(minute<10){minute='0'+minute;}var second=0;if(aMatches[4]){second=aMatches[4]*1;}if(second<10){second='0'+second;}oCell.c=hour+':'+minute+':'+second;}return oCell;};Zapatec.Grid.prototype.convertTimestampLocale=function(oCell){oCell=this.convertString(oCell);oCell.v=(new Date(parseInt(oCell.v)*1000)).toLocaleString();return oCell;};Zapatec.Grid.prototype.convertTimestampMMDDYYYY=function(oCell){oCell=this.convertString(oCell);var oDate=new Date(parseInt(oCell.v)*1000);var sMonth=oDate.getMonth()+1;if(sMonth<10){sMonth='0'+sMonth;}var sDay=oDate.getDate();if(sDay<10){sDay='0'+sDay;}var sYear=oDate.getYear();if(sYear<1900){sYear+=1900;}oCell.v=sMonth+'/'+sDay+'/'+sYear;return oCell;};Zapatec.Grid.prototype.convertTimestampDDMMYYYY=function(oCell){oCell=this.convertString(oCell);var oDate=new Date(parseInt(oCell.v)*1000);var sMonth=oDate.getMonth()+1;if(sMonth<10){sMonth='0'+sMonth;}var sDay=oDate.getDate();if(sDay<10){sDay='0'+sDay;}var sYear=oDate.getYear();if(sYear<1900){sYear+=1900;}oCell.v=sDay+'/'+sMonth+'/'+sYear;return oCell;};Zapatec.Grid.prototype.convertTimestampYYYYMMDD=function(oCell){oCell=this.convertString(oCell);var oDate=new Date(parseInt(oCell.v)*1000);var sMonth=oDate.getMonth()+1;if(sMonth<10){sMonth='0'+sMonth;}var sDay=oDate.getDate();if(sDay<10){sDay='0'+sDay;}var sYear=oDate.getYear();if(sYear<1900){sYear+=1900;}oCell.v=sYear+'/'+sMonth+'/'+sDay;return oCell;};Zapatec.Grid.prototype.convertBoolean=function(oCell){oCell=this.convertString(oCell);switch(oCell.c.toUpperCase()){case'0':case'F':case'FALSE':case'N':case'NO':case Zapatec.Grid.booleanValues[0].toUpperCase():oCell.c=0;break;default:oCell.c=1;}oCell.v=Zapatec.Grid.booleanValues[oCell.c];return oCell;};Zapatec.Grid.booleanValues=['No','Yes'];Zapatec.Grid.prototype.setBooleanValues=function(sNo,sYes){if(typeof sNo=='string'){Zapatec.Grid.booleanValues[0]=sNo;}if(typeof sYes=='string'){Zapatec.Grid.booleanValues[1]=sYes;}};Zapatec.Grid.prototype.convertBooleanTF=function(oCell){oCell=this.convertString(oCell);switch(oCell.c.toUpperCase()){case'0':case'F':case'FALSE':case'N':case'NO':case Zapatec.Grid.booleanTFValues[0].toUpperCase():oCell.c=0;break;default:oCell.c=1;}oCell.v=Zapatec.Grid.booleanTFValues[oCell.c];return oCell;};Zapatec.Grid.booleanTFValues=['False','True'];Zapatec.Grid.prototype.setBooleanTFValues=function(sFalse,sTrue){if(typeof sFalse=='string'){Zapatec.Grid.booleanTFValues[0]=sFalse;}if(typeof sTrue=='string'){Zapatec.Grid.booleanTFValues[1]=sTrue;}};Zapatec.Grid.convertByType={'string':'convertString','istring':'convertInsensitiveString','int':'convertInteger','intGerman':'convertIntegerGerman','integer':'convertInteger','integerGerman':'convertIntegerGerman','float':'convertFloat','floatGerman':'convertFloatGerman','date':'convertDate','time':'convertTime','timestamp':'convertTimestampLocale','timestampMMDDYYYY':'convertTimestampMMDDYYYY','timestampDDMMYYYY':'convertTimestampDDMMYYYY','timestampYYYYMMDD':'convertTimestampYYYYMMDD','boolean':'convertBoolean','booleanTF':'convertBooleanTF'};Zapatec.Grid.prototype.getConvertByType=function(sType){return Zapatec.Grid.convertByType[sType];};Zapatec.Grid.classByType={'string':'zpGridTypeString','istring':'zpGridTypeStringInsensitive','int':'zpGridTypeInt','intGerman':'zpGridTypeIntGerman','integer':'zpGridTypeInt','integerGerman':'zpGridTypeIntGerman','float':'zpGridTypeFloat','floatGerman':'zpGridTypeFloatGerman','date':'zpGridTypeDate','time':'zpGridTypeTime','timestamp':'zpGridTypeTimestampLocale','timestampMMDDYYYY':'zpGridTypeTimestampMMDDYYYY','timestampDDMMYYYY':'zpGridTypeTimestampDDMMYYYY','timestampYYYYMMDD':'zpGridTypeTimestampYYYYMMDD','boolean':'zpGridTypeBoolean','booleanTF':'zpGridTypeBooleanTF'};Zapatec.Grid.prototype.getClassByType=function(sType){return Zapatec.Grid.classByType[sType];};Zapatec.Grid.typeByClass={'zpGridTypeString':'string','zpGridTypeStringInsensitive':'istring','zpGridTypeInt':'int','zpGridTypeIntGerman':'intGerman','zpGridTypeFloat':'float','zpGridTypeFloatGerman':'floatGerman','zpGridTypeDate':'date','zpGridTypeTime':'time','zpGridTypeTimestampLocale':'timestamp','zpGridTypeTimestampMMDDYYYY':'timestampMMDDYYYY','zpGridTypeTimestampDDMMYYYY':'timestampDDMMYYYY','zpGridTypeTimestampYYYYMMDD':'timestampYYYYMMDD','zpGridTypeBoolean':'boolean','zpGridTypeBooleanTF':'booleanTF'};Zapatec.Grid.prototype.getTypeByClass=function(sClass){var aClasses=sClass.split(/\s+/);for(var iClass=0;iClass<aClasses.length;iClass++){var sType=Zapatec.Grid.typeByClass[aClasses[iClass]];if(typeof sType!='undefined'){return sType;}}return'string';};Zapatec.Grid.createType=function(funcConvert,sTypeName,sTypeClass){if(typeof funcConvert!='function'||typeof sTypeName!='string'||!sTypeName.length){return;}var sFuncName='convertCustom'+sTypeName.charAt(0).toUpperCase()+sTypeName.substr(1);Zapatec.Grid.prototype[sFuncName]=funcConvert;Zapatec.Grid.convertByType[sTypeName]=sFuncName;if(typeof sTypeClass=='string'&&sTypeClass.length){Zapatec.Grid.classByType[sTypeName]=sTypeClass;Zapatec.Grid.typeByClass[sTypeClass]=sTypeName;}};Zapatec.Grid.searchByType={'istring':'searchInsensitiveString'};Zapatec.Grid.prototype.getSearchByType=fu
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -