javascript

位置:IT落伍者 >> javascript >> 浏览文章

左侧是表头的JS表格控件


发布日期:2024年06月29日
 
左侧是表头的JS表格控件

今天项目中要用到该表格找了一遍发现没有合适的于是自己动手丰衣足食

左侧是表头的表格数据展现支持多行多表头固定表头的功能能够支持标题获取表格中的数据支持IE/CHROME 表格能够自适应根据内容行居中代码如下:<!DOCTYPE html PUBLIC "//WC//DTD XHTML Transitional//EN" "<html xmlns="<head runat="server"><title>Grid左侧固定测试</title><script src=LeftHeadGridjs></script><link href="LeftHeadGridcss" rel="stylesheet" type="text/css" /></head><body><form id="form" runat="server"><div id="testdiv" align="center"></div></form></body><script type="text/javascript" >var test = new LeftHeadGrid({id: "leftHeadGrid"width: title:"danielinbiti"perUnitWidth:rowHeads:[{width:""rowname:[{name:"日期"}{name:"数值"}]}]columnDatas:[{width:[]rows:[[][]]}]});testRenderTo("testdiv");</script></html>LeftHeadGridjs复制代码 代码如下:var LeftHeadGrid = function(config) {thisrowHeads = configrowHeads != null ? configrowHeads: [];//namethiscolumnDatas = configcolumnDatas != null ? configcolumnDatas: [];thiswidth = configwidth != null ? configwidth: "";thisid = configid != null ? configid: "TreGrid";thisperUnitWidth = configperUnitWidth != null ? configperUnitWidth: ;thisinnerWidth = ;thisinnerLWidth = ;thisheight = ;thistitle = configtitle != null ? configtitle: "";thisnoDataStr = confignoDataStr != null ? confignoDataStr: "no data";}LeftHeadGridprototypecreateGrid = function(){var totalwidth = ;var tableHtml = "<table>";for(var i=;i<thisrowHeadslength;i++){var obj = thisrowHeads[i];var width = objwidth;totalwidth = totalwidth + parseInt(width);var rownameobj = objrowname;for(var j=;j<rownameobjlength;j++){var nameobj = rownameobj[j];if(j==rownameobjlength){tableHtml = tableHtml + "<tr><td class=bluelast width=" + width + "px>" + nameobjname + "</td></tr>";}else{tableHtml = tableHtml + "<tr><td class=bluefirst width=" + width + "px>" + nameobjname + "</td></tr>";}thisheight = thisheight + ;}}tableHtml = tableHtml + "</table>";var headHtml = "<div class=leftheadcss style=width:" + totalwidth + "px;>";headHtml = headHtml + tableHtml + "</div>";thisinnerLWidth = totalwidth;thisinnerWidth = thiswidthtotalwidth;return headHtml;}LeftHeadGridprototypeRenderTo =function(divId){//var innerWidth = thiswidth;var headHtml = thiscreateGrid();var html = "<div id=outframe class=outframecss style=width:" + thiswidth + "px;>"+ headHtml+ "<div id=dataframe class=dataframecss style=width:" + thisinnerWidth + "px;>"+ "<div id=leftgriddataview class=innerdivcss>"+ "</div>"+ "</div>"+ "</div>"html = "<div id=divtitle class=grittitle style=width:" + thiswidth + "px;height:px><big>" + thistitle + "</big></div>"+ html + "</div>";documentgetElementById(divId)innerHTML = html;thisshow();}LeftHeadGridprototypeshow = function(){if(thiscolumnDatas && thiscolumnDataslength>){var obj = thiscolumnDatas[];var widthArr = objwidth;var rows = objrows;var totalWidth = ;for(var i=;i<widthArrlength;i++){widthArr[i] = parseInt(widthArr[i])*thisperUnitWidth;totalWidth = totalWidth + widthArr[i];}var tableHtml = "<table width="+totalWidth +">";for(var i=;i<rowslength;i++){var rowvalueArr = rows[i];tableHtml = tableHtml + "<tr>";for(var j=;j<rowvalueArrlength;j++){tableHtml = tableHtml + "<td width="+widthArr[j]+"px>" + rowvalueArr[j] + "</td>";}tableHtml = tableHtml + "</tr>";}tableHtml = tableHtml + "</table>";if(thisinnerWidth>totalWidth){documentgetElementById("dataframe")stylewidth=(parseInt(totalWidth))+"px";documentgetElementById("divtitle")stylewidth=(parseInt(thisinnerLWidth)+parseInt(totalWidth))+"px";documentgetElementById("outframe")stylewidth=(parseInt(thisinnerLWidth)+parseInt(totalWidth)+)+"px";}documentgetElementById("leftgriddataview")innerHTML = tableHtml;}else{documentgetElementById("leftgriddataview")styleheight=(thisheight+)+"px";documentgetElementById("leftgriddataview")innerHTML = thisnoDataStr;}}LeftHeadGridprototypeaddData = function(data){thiscolumnDatas = data;thisshow();}LeftHeadGridprototypegetData = function(){var rtnObj = new Array();if(thiscolumnDatas && thiscolumnDataslength>){var obj = thiscolumnDatas[];var widthArr = objwidth;var rows = objrows;for(var i=;i<rowslength;i++){var rowvalueArr = rows[i];for(var j=;j<rowvalueArrlength;j++){if(j==){rtnObj[i] = rowvalueArr[j];}else{rtnObj[i] = rtnObj[i] + "" + rowvalueArr[j];}}}}return rtnObj;}LeftHeadGridprototypegetHead = function(){var rtnObj = new Array();for(var i=;i<thisrowHeadslength;i++){var obj = thisrowHeads[i];var rownameobj = objrowname;for(var j=;j<rownameobjlength;j++){var nameobj = rownameobj[j];if(j==){rtnObj[i] = nameobjname;}else{rtnObj[i] = rtnObj[i] + "" + nameobjname;}}}return rtnObj;}如果有需要各位可以自己更改完整源码:代码如下:var LeftHeadGrid = function(config) {thisrowHeads = configrowHeads != null ? configrowHeads: [];//namethiscolumnDatas = configcolumnDatas != null ? configcolumnDatas: [];thiswidth = configwidth != null ? configwidth: "";thisid = configid != null ? configid: "TreGrid";thisperUnitWidth = configperUnitWidth != null ? configperUnitWidth: ;thisinnerWidth = ;thisinnerLWidth = ;thisheight = ;thistitle = configtitle != null ? configtitle: "";thisnoDataStr = confignoDataStr != null ? confignoDataStr: "no data";}LeftHeadGridprototypecreateGrid = function(){var totalwidth = ;var tableHtml = "<table>";for(var i=;i<thisrowHeadslength;i++){var obj = thisrowHeads[i];var width = objwidth;totalwidth = totalwidth + parseInt(width);var rownameobj = objrowname;for(var j=;j<rownameobjlength;j++){var nameobj = rownameobj[j];if(j==rownameobjlength){tableHtml = tableHtml + "<tr><td class=bluelast width=" + width + "px>" + nameobjname + "</td></tr>";}else{tableHtml = tableHtml + "<tr><td class=bluefirst width=" + width + "px>" + nameobjname + "</td></tr>";}thisheight = thisheight + ;}}tableHtml = tableHtml + "</table>";var headHtml = "<div class=leftheadcss style=width:" + totalwidth + "px;>";headHtml = headHtml + tableHtml + "</div>";thisinnerLWidth = totalwidth;thisinnerWidth = thiswidthtotalwidth;return headHtml;}LeftHeadGridprototypeRenderTo =function(divId){//var innerWidth = thiswidth;var headHtml = thiscreateGrid();var html = "<div id=outframe class=outframecss style=width:" + thiswidth + "px;>"+ headHtml+ "<div id=dataframe class=dataframecss style=width:" + thisinnerWidth + "px;>"+ "<div id=leftgriddataview class=innerdivcss>"+ "</div>"+ "</div>"+ "</div>"html = "<div id=divtitle class=grittitle style=width:" + thiswidth + "px;height:px><big>" + thistitle + "</big></div>"+ html + "</div>";documentgetElementById(divId)innerHTML = html;thisshow();}LeftHeadGridprototypeshow = function(){if(thiscolumnDatas && thiscolumnDataslength>){var obj = thiscolumnDatas[];var widthArr = objwidth;var rows = objrows;var totalWidth = ;for(var i=;i<widthArrlength;i++){widthArr[i] = parseInt(widthArr[i])*thisperUnitWidth;totalWidth = totalWidth + widthArr[i];}var tableHtml = "<table width="+totalWidth +">";for(var i=;i<rowslength;i++){var rowvalueArr = rows[i];tableHtml = tableHtml + "<tr>";for(var j=;j<rowvalueArrlength;j++){tableHtml = tableHtml + "<td width="+widthArr[j]+"px>" + rowvalueArr[j] + "</td>";}tableHtml = tableHtml + "</tr>";}tableHtml = tableHtml + "</table>";if(thisinnerWidth>totalWidth){documentgetElementById("dataframe")stylewidth=(parseInt(totalWidth))+"px";documentgetElementById("divtitle")stylewidth=(parseInt(thisinnerLWidth)+parseInt(totalWidth))+"px";documentgetElementById("outframe")stylewidth=(parseInt(thisinnerLWidth)+parseInt(totalWidth)+)+"px";}documentgetElementById("leftgriddataview")innerHTML = tableHtml;}else{documentgetElementById("leftgriddataview")styleheight=(thisheight+)+"px";documentgetElementById("leftgriddataview")innerHTML = thisnoDataStr;}}LeftHeadGridprototypeaddData = function(data){thiscolumnDatas = data;thisshow();}LeftHeadGridprototypegetData = function(){var rtnObj = new Array();if(thiscolumnDatas && thiscolumnDataslength>){var obj = thiscolumnDatas[];var widthArr = objwidth;var rows = objrows;for(var i=;i<rowslength;i++){var rowvalueArr = rows[i];for(var j=;j<rowvalueArrlength;j++){if(j==){rtnObj[i] = rowvalueArr[j];}else{rtnObj[i] = rtnObj[i] + "" + rowvalueArr[j];}}}}return rtnObj;}LeftHeadGridprototypegetHead = function(){var rtnObj = new Array();for(var i=;i<thisrowHeadslength;i++){var obj = thisrowHeads[i];var rownameobj = objrowname;for(var j=;j<rownameobjlength;j++){var nameobj = rownameobj[j];if(j==){rtnObj[i] = nameobjname;}else{rtnObj[i] = rtnObj[i] + "" + nameobjname;}}}return rtnObj;}               

上一篇:使用javascript过滤html的字符串(注释标记法)

下一篇:Javascript实现刷新网页代码汇总