📄 zpgrid.js
字号:
this.id+"',["+sCols+"])";oChoice.clearall="Zapatec.Grid.checkboxClearAllOnClick('"+this.id+"',["+sCols+"])";}aChoices.push(oChoice);}oFilterOut.callback(aChoices);}else if(this.visualizeFilterOut){this.visualizeFilterOut(oFilterOut,aVals);}}};Zapatec.Grid.prototype.getColumnRange=function(oArg){if(!oArg||typeof oArg.column=='undefined'){return null;}var aCols=oArg.column;if(!(aCols instanceof Array)){var oField=this.fields[oArg.column];if(!oField){return null;}if(typeof oField.columnRange!='undefined'){return oField.columnRange;}aCols=[oArg.column];}var aKeys=[];var oKeys={};var aRows=oArg.filtered?this.filteredRows:this.rows;for(var iRow=0;iRow<aRows.length;iRow++){var oRow=aRows[iRow];if(!oRow){continue;}for(var iCol=0;iCol<aCols.length;iCol++){var oCell=oRow.cells[aCols[iCol]];if(!oCell){continue;}var sKey=this.getCellValueString(oCell);if(sKey.length&&typeof oKeys[sKey]=='undefined'){aKeys.push({v:sKey,c:this.getCellValueCompare(oCell),o:this.getCellValueOriginal(oCell)});oKeys[sKey]=true;}}}if(!aKeys.length){return null;}aKeys.sort(function(leftVal,rightVal){if(leftVal.c<rightVal.c){return-1;}if(leftVal.c>rightVal.c){return 1;}return 0;});var iLastKey=aKeys.length-1;return{min:aKeys[0].c,minValue:aKeys[0].v,minOrig:aKeys[0].o,max:aKeys[iLastKey].c,maxValue:aKeys[iLastKey].v,maxOrig:aKeys[iLastKey].o,values:aKeys};};Zapatec.Grid.prototype.recordsDisplayed=function(){if(this.config.dataOnDemand&&typeof this.data.displayedRows!='undefined'){return this.data.displayedRows*1;}return this.filteredRows.length;};Zapatec.Grid.prototype.setDisplayedRows=function(iRows){if(this.config.dataOnDemand){this.data.displayedRows=iRows;}};Zapatec.Grid.prototype.totalRecords=function(){if(this.config.dataOnDemand&&typeof this.data.totalRows!='undefined'){return this.data.totalRows*1;}return this.rows.length;};Zapatec.Grid.prototype.setTotalRows=function(iRows){if(this.config.dataOnDemand){this.data.totalRows=iRows;}};Zapatec.Grid.prototype.getId=function(){return this.id;};Zapatec.Grid.prototype.getStyle=function(){if(this.data&&this.data.style){return this.data.style;}return'';};Zapatec.Grid.prototype.getHeaderStyle=function(){if(this.data&&this.data.headerStyle){return this.data.headerStyle;}return'';};Zapatec.Grid.prototype.getRows=function(){return this.rows;};Zapatec.Grid.prototype.getFilteredRows=function(){return this.filteredRows;};Zapatec.Grid.prototype.getRowId=function(oRow){if(oRow){return oRow.i;}};Zapatec.Grid.prototype.getRowIdByPrimaryKey=function(sKey){return this.getRowId(this.getRowByPrimaryKey(sKey));};Zapatec.Grid.prototype.getRowNumber=function(oRow){if(oRow){var iRowId=this.getRowId(oRow);var aRows=this.applyPaging();for(var iRow=0;iRow<aRows.length;iRow++){if(this.getRowId(aRows[iRow])==iRowId){return iRow;}}}};Zapatec.Grid.prototype.getRowIndexById=function(iRowId){for(var iRow=0;iRow<this.rows.length;iRow++){if(this.getRowId(this.rows[iRow])==iRowId){return iRow;}}};Zapatec.Grid.prototype.getRowStyle=function(oRow){if(oRow&&oRow.style){return oRow.style;}return'';};Zapatec.Grid.prototype.getRowSelected=function(oRow){return(oRow&&oRow.selected);};Zapatec.Grid.prototype.getRowById=function(iRowId){return this.rowsIndex[iRowId];};Zapatec.Grid.prototype.getRowByPrimaryKey=function(sKey){if(this.primaryKey){return this.primaryKey[sKey];}};Zapatec.Grid.prototype.getRowByCell=function(oCell){if(oCell){return this.getRowById(oCell.r);}};Zapatec.Grid.prototype.getRowCells=function(oRow){if(oRow&&oRow.cells instanceof Array){return oRow.cells;}};Zapatec.Grid.prototype.setRowStyle=function(oRow,sStyle){if(oRow instanceof Object){oRow.style=sStyle;}return oRow;};Zapatec.Grid.prototype.getFields=function(oArg){var aFields=this.fields;if(oArg&&oArg.visible){var aVisibleFields=[];var iFields=aFields.length;var oField;for(var iField=0;iField<iFields;iField++){oField=aFields[iField];if(!oField.hidden){aVisibleFields.push(oField);}}aFields=aVisibleFields;}return aFields;};Zapatec.Grid.prototype.getFieldId=function(oField){if(oField){return oField.i;}};Zapatec.Grid.prototype.getFieldTitle=function(oField){if(oField&&oField.title){return oField.title;}return'';};Zapatec.Grid.prototype.getFieldType=function(oField){if(oField){return oField.dataType;}};Zapatec.Grid.prototype.getFieldWidth=function(oField){if(oField&&oField.columnWidth){return oField.columnWidth;}return'';};Zapatec.Grid.prototype.getFieldStyle=function(oField){if(oField&&oField.style){return oField.style;}return'';};Zapatec.Grid.prototype.getFieldSpanned=function(oField){if(!oField){return;}var iSpan=parseInt(oField.span);if(isNaN(iSpan)){var iId=oField.i;for(var iOffset=1;iOffset<=iId;iOffset++){oField=this.fields[iId-iOffset];if(!oField||!oField.hidden){return;}iSpan=parseInt(oField.span);if(!isNaN(iSpan)){break;}}}if(isNaN(iSpan)||iSpan<=0){return;}var aFields=[];var iSpanned=0;for(var iOffset=0;iOffset<iSpan;iOffset++){var oF=this.fields[oField.i+iOffset];if(!oF){continue;}if(iOffset>0&&!isNaN(parseInt(oF.span))){break;}aFields.push(oF);if(!oF.hidden){iSpanned++;}}if(!iSpanned){return;}return{spanned:iSpanned,fields:aFields};};Zapatec.Grid.prototype.getFieldSpan=function(oField){if(oField){var iSpan=parseInt(oField.span);if(!isNaN(iSpan)){return Math.max(iSpan,0);}}return 0;};Zapatec.Grid.prototype.getFieldSpanTitle=function(oField){if(oField&&oField.spanTitle){return oField.spanTitle;}return'';};Zapatec.Grid.prototype.getFieldSpanStyle=function(oField){if(oField&&oField.spanStyle){return oField.spanStyle;}return'';};Zapatec.Grid.prototype.getFieldHidden=function(oField){if(oField){return oField.hidden;}};Zapatec.Grid.prototype.getFieldNosort=function(oField){if(oField){return oField.nosort;}};Zapatec.Grid.prototype.getFieldSorted=function(oField){if(oField){return oField.sorted;}};Zapatec.Grid.prototype.getFieldSortedDesc=function(oField){if(oField){return oField.sortedDesc;}};Zapatec.Grid.prototype.getFieldOnclick=function(oField){if(oField&&!oField.nosort){return"Zapatec.Grid.sort('"+this.id+"','"+oField.i+"')";}return'';};Zapatec.Grid.prototype.getFieldById=function(iFieldId){return this.fields[iFieldId];};Zapatec.Grid.prototype.getFieldByCell=function(oCell){if(oCell){return this.getFieldById(oCell.i);}};Zapatec.Grid.prototype.getCellId=function(oCell){if(oCell){return oCell.i;}};Zapatec.Grid.prototype.getCellRowId=function(oCell){if(oCell){return oCell.r;}};Zapatec.Grid.prototype.getCellRowNumber=function(oCell){if(oCell){var iRowId=this.getCellRowId(oCell);var aRows=this.applyPaging();for(var iRow=0;iRow<aRows.length;iRow++){if(this.getRowId(aRows[iRow])==iRowId){return iRow;}}}};Zapatec.Grid.prototype.getCellByRow=function(oRow,iCellId){var aCells=this.getRowCells(oRow);if(aCells){return aCells[iCellId];}};Zapatec.Grid.prototype.getCellById=function(iRowId,iCellId){return this.getCellByRow(this.getRowById(iRowId),iCellId);};Zapatec.Grid.prototype.getCellValue=function(oCell){if(!oCell){return;}return oCell.v;};Zapatec.Grid.prototype.getCellValueString=function(oCell){return this.getCellValue(oCell)+'';};Zapatec.Grid.prototype.getCellValueCompare=function(oCell){if(!oCell){return'';}if(typeof oCell.c!='undefined'){return oCell.c;}return this.getCellValue(oCell);};Zapatec.Grid.prototype.getCellValueOriginal=function(oCell){if(!oCell){return'';}if(typeof oCell.o!='undefined'){return oCell.o;}return this.getCellValue(oCell);};Zapatec.Grid.prototype.getCellStyle=function(oCell,iRow){if(!oCell){return'';}var sStyle='';if(typeof this.config.funcStyle=='function'){sStyle=this.config.funcStyle(this,oCell,iRow);}if(!sStyle){sStyle=oCell.style;}return sStyle;};Zapatec.Grid.prototype.getCellSelected=function(oCell){return(oCell&&oCell.selected);};Zapatec.Grid.prototype.getCellDataType=function(oCell){var oField=this.getFieldByCell(oCell);if(oField){return oField.dataType;}};Zapatec.Grid.prototype.getCellData=function(oCell,iMode){if(!oCell){return'undefined';}if(!iMode){iMode=1;}if((iMode==1&&!this.config.show_asis)||iMode==2){return this.getCellValueString(oCell);}var sData=this.getCellValueOriginal(oCell)+'';if(iMode==4){return sData;}if(typeof this.config.show_asis=='object'){if(typeof this.config.show_asis.funcShow=='function'){sData=this.config.show_asis.funcShow(this,oCell);}if(this.config.show_asis.bBoth){sData='<u>'+sData+'</u><br>'+this.getCellValueString(oCell);}}return sData;};Zapatec.Grid.prototype.setFieldTitle=function(oField,sTitle){if(!oField){return 0;}oField.title=sTitle;var oSpan=document.getElementById(['zpGrid',this.id,'Col',oField.i,'TitleSpan'].join(''));if(oSpan){oSpan.innerHTML=sTitle;}return 1;};Zapatec.Grid.prototype.setCellValue=function(oCell,value){if(!oCell){oCell={};}else{oCell.previousState=null;oCell.previousState=Zapatec.Utils.clone(oCell);}oCell.v=value;return this.convertCell(oCell);};Zapatec.Grid.prototype.revertCell=function(oArg){var iRowId=parseInt(oArg.rowId);var oRow=oArg.row;var iCellId=parseInt(oArg.cellId);var oCell=oArg.cell;if(!oRow){if(!isNaN(iRowId)){oRow=this.getRowById(iRowId);}else if(oCell){oRow=this.getRowByCell(oCell);}if(!oRow){return null;}}if(isNaN(iCellId)){iCellId=this.getCellId(oCell);if(typeof iCellId!='number'){return null;}}var aCells=oRow.cells;if(aCells){oCell=aCells[iCellId];if(oCell){var oPrevState=oCell.previousState;if(oPrevState){oCell.previousState=null;oPrevState.previousState=Zapatec.Utils.clone(oCell);aCells[iCellId]=oCell=oPrevState;}return oCell;}}return null;};Zapatec.Grid.prototype.revertRow=function(oArg){var iRowId=parseInt(oArg.rowId);var oRow=oArg.row;if(!oRow){if(!isNaN(iRowId)){oRow=this.getRowById(iRowId);}if(!oRow){return null;}}var aCells=oRow.cells;if(!(aCells instanceof Array)){return null;}var iCells=aCells.length;for(var iCell=0;iCell<iCells;iCell++){this.revertCell({row:oRow,cellId:iCell});}return oRow;};Zapatec.Grid.prototype.setCellStyle=function(oCell,sStyle){if(oCell instanceof Object){oCell.style=sStyle;}return oCell;};Zapatec.Grid.prototype.hideColumns=function(oArg){var aColumns=oArg.columns;if(!(aColumns instanceof Array)){if(typeof aColumns=='undefined'){return;}aColumns=[aColumns];}var iColumns=aColumns.length;var iColumn,oColumn;for(iColumn=0;iColumn<iColumns;iColumn++){oColumn=this.getFieldById(aColumns[iColumn]);if(oColumn){oColumn.hidden=true;}}if(!oArg.noRefresh){this.refresh();}};Zapatec.Grid.prototype.showColumns=function(oArg){if(!(oArg.columns instanceof Array)){if(typeof oArg.columns=='undefined'){return;}oArg.columns=[oArg.columns];}for(var iCol=0;iCol<oArg.columns.length;iCol++){var oCol=this.getFieldById(oArg.columns[iCol]);if(oCol){oCol.hidden=false;if(!oArg.noRefresh){this.refresh();}}}};Zapatec.Grid.prototype.receiveData=function(oArg){Zapatec.Grid.SUPERclass.receiveData.call(this,oArg);if(!oArg.data){return;}var aRows=oArg.data;if(!(aRows instanceof Array)){aRows=[aRows];}for(var iRow=0;iRow<aRows.length;iRow++){var aCells=aRows[iRow];if(aCells.cells){break;}if(!(aCells instanceof Array)){aCells=[aCells];}var oRow={cells:[]};for(var iCell=0;iCell<aCells.length;iCell++){var oCell=aCells[iCell];if(typeof oCell.v!='undefined'){oRow.cells.push(oCell);}else{oRow.cells.push({v:oCell});}}aRows[iRow]=oRow;}this.splice({atRow:0,howMany:this.totalRecords(),rows:Zapatec.Utils.clone(aRows)});};Zapatec.Grid.prototype.editSelectedRows=function(oEditor){if(!oEditor||!oEditor.receiveData){return;}var aRows=this.getSelectedRows();if(!aRows.length){alert(this.getMessage('errorSelectRow'));return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -