我做的reportview代码放出
Report View Control 1.0
file list:
reportview.jsp
reportview.css
sample.html
--------------------------------------------------------
//reportview.jsp
///////////////////////////////////////////////////
/////// Report View Control 1.0
///////////////////////////////////////////////////
//Author : guliang
//Last modified at : 2002-10-23
///////////////////////////////////////////////////
document.writeln('<link rel="stylesheet" href="reportview.css">');
//Construct function
//id: must same as new obj name
function ReportView(id,width,height,lineType,ReadOnly,MultLine,Fixed)
{
//Properties
this.id = "";
if (id!="")
{
this.id = id;
}
this.headLayerId = this.id + "_HeadLayer";
this.headTableId = this.id + "_HeadTable";
this.contentLayerId = this.id + "_ContentLayer";
this.contentTableId = this.id + "_ContentTable";
this.bgColor = "#FFFFFF";
this.fontColor = "#3300CC";
this.selectFontColor="#FFFFFF";
this.selectBgColor="#000000";
this.width = 200;
this.height = 200;
this.lineType = "NOLINE";//NOLINE VLINE VHLINE
this.bReadOnly = false;//true:READONLY ;false:WRITE
this.bMultLine = false;//true:MultLine ;false:SingleLine
this.Fixed = "auto";//true:col width could not changed ;false:col width can exceeded by data
this.selectLineNumber = -1;//select line number(get)
//Methods
this.setTitle=setTitle;
this.addLine=addLine;
this.addLines=addLines;
this.delLine=delLine;
this.getLine=getLine;//get line obj
this.getCell=getCell;//get cell obj
this.onSelect=onSelect;
// this.onDoubleClick=onDoubleClick;
this.getSelectLineNumber=getSelectLineNumber;
this.appendOnSelect=appendOnSelect;
this.setValue=setValue;
this.getValue=getValue;
this.getLinesNumber=getLinesNumber;//get number of data lines
//init
if (typeof(lineType)!="undefined" && (lineType.toUpperCase()=="NOLINE" || lineType.toUpperCase()=="VLINE" || lineType.toUpperCase()=="VHLINE"))
{
this.lineType = lineType.toUpperCase();
}
if (width > 0)
{
this.width = width;
}
if (height > 0)
{
this.height = height;
}
if (typeof(ReadOnly)!="undefined" && ReadOnly.toUpperCase() != "WRITE")
{
this.bReadOnly = true;
this.bgColor = "#CCCCCC";
}
if (typeof(MultLine)!="undefined" && MultLine.toUpperCase() == "MULTLINE")
{
this.bMultLine = true;
}
if (typeof(Fixed)!="undefined" && Fixed.toUpperCase() == "FIXED")
{
this.Fixed = "fixed";
}
//create titlebar
document.writeln('<TABLE border="1" class="reportview" id="' + this.id + '"><TR><TD>');
document.writeln('<DIV id="'+ this.headLayerId +'" style=" width:'+ this.width +';position: absolute; z-index:2">');
document.writeln(' ');
document.writeln('</DIV>');
//create content
document.writeln('<DIV id="' + this.contentLayerId + '" style="width:'+ this.width +';height:'+ this.height +';background-color:'+ this.bgColor +';overflow-x:auto;overflow-y:scroll; z-index:1;">');
document.writeln('</DIV>');
document.writeln('</TD></TR></TABLE>');
//Objects
this.headLayer = document.all[this.headLayerId];
this.contentLayer = document.all[this.contentLayerId];
//Properties(private)
this.appendOnSelectCmd= "";
//Methods(private)
this.fitTab=fitTab;
this.headingUpdate=headingUpdate;
this.synchronizeHeader=synchronizeHeader;
this.findPosX=findPosX;
}
//set title content and table width
function setTitle(str,tableWidth)
{
if (str=="")
{
str='<td> </td>';
}
if(typeof(tableWidth)=="undefined" || tableWidth<=0)
{
tableWidth = this.width;
}
else if (tableWidth>0 && tableWidth<this.width)
{
this.width = tableWidth;
}
// alert(tableWidth);
tbStr = '<TABLE id="'+ this.headTableId +'" border="0" cellpadding="2" cellspacing="0" style="table-layout:' + this.Fixed + '" class="lable">';
// tbStr += '<TR>';
tbStr += str;
// tbStr += '</TR>';
tbStr += '</TABLE>'
this.headLayer.innerHTML = tbStr;
//obj
this.headTable = document.all[this.headTableId];
tbStr = '<TABLE cellpadding="2" cellspacing="0" id="'+ this.contentTableId +'" class="'+ this.lineType +'" bgcolor="'+ this.bgColor +'" style="table-layout:'+ this.Fixed +'" onclick="'+this.id+'.onSelect()">';// style="table-layout:fixed" ondblclick="'+this.id+'.onDoubleClick()"
tbStr += str;
tbStr += '</TABLE>'
this.contentLayer.innerHTML = tbStr;
//obj
this.contentTable = document.all[this.contentTableId];
this.contentTable.rows[0].height = this.headTable.rows[0].offsetHeight;
//set content table width
document.all[this.contentTableId].style.width = tableWidth;
//adding scrollBar width to the dataContainer div
document.all[this.contentLayerId].style.width = document.all[this.contentTableId].offsetWidth + getScrollBarWidth ();
//adding scrollBar width to the headContainer div
document.all[this.headLayerId].style.width = document.all[this.contentTableId].offsetWidth;
this.fitTab();
// this.synchronizeHeader();
//attach scroll even to content layer
document.all[this.contentLayerId].attachEvent("onscroll",new Function(this.id+'.headingUpdate()'));
//attach even to content layer
document.all[this.contentTableId].attachEvent("onselectstart",cancelSelect);
}
//下一贴继续