Hi,
This javascript creates a table that has a header and side column that
do not move while scrolling through the table. I need to convert this
to vb script. Can anybody help, or do you have code in vb (asp) that
would do the same thing?
<html>
<head>
<title>Scrollin g Grid Demo</title>
<script type="text/javascript">
function Grid(name, data)
{
// store arguments
this.name = name;
this.data = data;
var cursor = document.all ? "hand" : "pointer";
// persist object for later use.
window[name] = this;
// initialize internal properties.
this.xOffset = 0;
this.yOffset = 0;
// render table
var aStr = new Array;
aStr.push('<tab le border=1 cellpadding=0 cellspacing=0 id="' +
this.name + '">');
// column header row
aStr.push('<tr> ');
aStr.push('<td> </td>');
for ( var j = 0; j < this.data.nCol; j++ )
{
aStr.push('<th width=' + this.data.nCell Width + '><span>' +
this.data.colHe aders[j] + '</span></th>');
}
aStr.push('<td width=20> </td>');
aStr.push('</tr>');
// data rows
for ( var i = 0; i < this.data.nRow; i++ )
{
aStr.push('<tr> ');
aStr.push('<th valign=top width=' + this.data.nCell Width + '><span>'
+ this.data.rowHe aders[i] + '</span></th>');
for ( j = 0; j < this.data.nCol; j++ )
aStr.push('<td> <span style="overflow :hidden;width:' +
this.data.nCell Width + 'px;height:' + this.data.nCell Height + 'px;
text-align:center;"> ' + this.data.value s[i][j] + '</span></td>');
// add the vertical scroll bar
if ( i == 0 )
{
aStr.push('<td rowspan=' + this.data.nRow + ' valign=top>');
aStr.push('<div style="position :relative;heigh t:' + nHeight +
'px;width:20px; ">');
// add the scroll indicator
var nHeight = this.data.nRow * this.data.nCell Height +
(this.data.nRow-1) * 2;
var nStartHeight = 1;
var nBarHeight = Math.floor(nHei ght * this.data.nRow /
this.data.rowHe aders.length);
var nEndHeight = nHeight - nStartHeight - nBarHeight;
aStr.push('<div style="position :absolute;heigh t=120px;">');
aStr.push('<tab le width=20 height=' + nHeight + ' border=0
cellpadding=0 cellspacing=0>' );
aStr.push('<tr> <td height=1><div></div></td></tr>');
aStr.push('<tr> <td height=' + nBarHeight + ' bgcolor="#33cc3 3"
height=20><div> </div></td></tr>');
aStr.push('<tr> <td height=' + nEndHeight +
'><div></div></td></tr>');
aStr.push('</table>');
aStr.push('</div>');
// add the scroll buttons
aStr.push('<div style="position :absolute;heigh t=' + nHeight +
'px;width=20px; ">');
aStr.push('<tab le width=20 height=' + nHeight + ' border=0
cellpadding=0 cellspacing=0>' );
aStr.push('<tr> <td width=' + nHeight/2 + ' valign=top
align=center><d iv style="cursor:' + cursor + ';" onclick="window .' +
this.name + '.scroll(0,-1);">^</div></td></tr>');
aStr.push('<tr> <td width=' + nHeight/2 + ' valign=bottom
align=center><d iv style="cursor:' + cursor + ';" onclick="window .' +
this.name + '.scroll(0,1);" >v</div></td></tr>');
aStr.push('</table>');
aStr.push('</div>');
aStr.push('</div>');
aStr.push('</td>');
}
aStr.push('</tr>');
}
// add the horizontal scroll bar
aStr.push('<tr> ');
aStr.push('<td> </td>');
aStr.push('<td colspan=' + this.data.nCol + '>');
aStr.push('<div style="position :relative;width =' + nWidth +
'px;height=20px ;">');
// the scroll indicator part
var nWidth = this.data.nCol * this.data.nCell Width +
(this.data.nCol-1) * 2;
var nStartWidth = 1;
var nBarWidth = Math.floor(nWid th * this.data.nCol /
this.data.colHe aders.length);
var nEndWidth = nWidth - nStartWidth - nBarWidth;
aStr.push('<div style="position :absolute;width =' + nWidth +
'px;left:0px;to p:0px">');
aStr.push('<tab le width=' + nWidth + ' border=0 cellpadding=0
cellspacing=0>' );
aStr.push('<tr> ');
aStr.push('<td width=1><div></div></td>');
aStr.push('<td width=' + nBarWidth + ' bgcolor="#33cc3 3"
height=20><div> </div></td>');
aStr.push('<td width=' + nEndWidth + '><div></div></td>');
aStr.push('</tr>');
aStr.push('</table>');
aStr.push('</div>');
// the scroll buttons
aStr.push('<div style="position :absolute;width =' + nWidth +
'px;;left:0px;t op:0px">');
aStr.push('<tab le width=' + nWidth + ' border=0 cellpadding=0
cellspacing=0>' );
aStr.push('<tr> ');
aStr.push('<td width=' + nWidth/2 + ' align=left><div style="cursor:'
+ cursor + ';width:20px;" onclick="window .' + this.name +
'.scroll(-1,0);"><</div></td>');
aStr.push('<td width=' + nWidth/2 + ' align=right><di v
style="cursor:' + cursor + ';width:20px;" onclick="window .' +
this.name + '.scroll(1,0);" >></div></td>');
aStr.push('</tr>');
aStr.push('</table>');
aStr.push('</div>');
aStr.push('&nbs p;');
aStr.push('</div>');
aStr.push('</td>');
aStr.push('<td> </td>');
aStr.push('</tr>');
// finally close off the table
aStr.push('</table>');
// write HTML to document.
document.write( aStr.join(''));
}
// locate all spans and control points
Grid.prototype. init = function()
{
// if already initialized, return
if ( this.oTable ) return;
this.oTable = document.getEle mentById(this.n ame);
// get all <span> elements within the table
var aSpan = this.oTable.get ElementsByTagNa me('span');
var n = 0;
// the first few are all column headers
this.aColSpan = new Array;
for ( var j = 0; j < this.data.nCol; j++ )
this.aColSpan.p ush(aSpan[n++]);
// the remainder are row headers and cells
this.aRowSpan = new Array;
this.aCellSpan = new Array;
for ( var i = 0; i < this.data.nRow; i++ )
{
this.aRowSpan.p ush(aSpan[n++]);
this.aCellSpan. push(new Array());
for ( j = 0; j < this.data.nCol; j++ )
this.aCellSpan[i].push(aSpan[n++]);
}
// get all the <div> elements
var aDiv = this.oTable.get ElementsByTagNa me('div');
// the vertical scroll is in aDiv[2]
this.aVerticalT D = aDiv[1].getElementsByT agName('td');
// the horizontal scroll is in aDiv[10]
this.aHorizonta lTD = aDiv[9].getElementsByT agName('td');
}
// fill all the column/row headers and cell values
// and adjust the scroll bars
Grid.prototype. fill = function()
{
this.init();
// headers
for ( var j = 0; j < this.data.nCol; j++ )
this.aColSpan[j].innerHTML = this.data.colHe aders[j + this.xOffset];
for ( var i = 0; i < this.data.nRow; i++ )
this.aRowSpan[i].innerHTML = this.data.rowHe aders[i + this.yOffset];
// values
for ( i = 0; i < this.data.nRow; i++ )
for ( j = 0; j < this.data.nCol; j++ )
this.aCellSpan[i][j].innerHTML = this.data.value s[i +
this.yOffset][j + this.xOffset];
// scroll bars
var nHeight = this.data.nRow * this.data.nCell Height +
(this.data.nRow-1) * 2;
var nStartHeight = Math.floor(nHei ght * this.yOffset /
this.data.rowHe aders.length);
if ( nStartHeight == 0 ) nStartHeight++;
var nBarHeight = Math.floor(nHei ght * this.data.nRow /
this.data.rowHe aders.length);
var nEndHeight = nHeight - nStartHeight - nBarHeight;
if ( nEndHeight == 0 ) nStartHeight--, nEndHeight++;
this.aVerticalT D[0].height = nStartHeight;
this.aVerticalT D[1].height = nBarHeight;
this.aVerticalT D[2].height = nEndHeight;
var nWidth = this.data.nCol * this.data.nCell Width +
(this.data.nCol-1) * 2;
var nStartWidth = Math.floor(nWid th * this.xOffset /
this.data.colHe aders.length);
if ( nStartWidth == 0 ) nStartWidth++;
var nBarWidth = Math.floor(nWid th * this.data.nCol /
this.data.colHe aders.length);
var nEndWidth = nWidth - nStartWidth - nBarWidth;
if ( nEndWidth == 0 ) nEndWidth++, nStartWidth--;
this.aHorizonta lTD[0].width = nStartWidth;
this.aHorizonta lTD[1].width = nBarWidth;
this.aHorizonta lTD[2].width = nEndWidth;
}
Grid.prototype. scroll = function(x,y)
{
this.xOffset += x;
if ( this.xOffset < 0 ) this.xOffset = 0;
if ( this.xOffset > this.data.colHe aders.length - this.data.nCol )
this.xOffset = this.data.colHe aders.length - this.data.nCol;
this.yOffset += y;
if ( this.yOffset < 0 ) this.yOffset = 0;
if ( this.yOffset > this.data.rowHe aders.length - this.data.nRow )
this.yOffset = this.data.rowHe aders.length - this.data.nRow;
this.fill();
}
</script>
</head>
<body>
ggg
<script>
var currencies = ["ARS","ATS","AU D","BBD","BEF", "BGL","BMD","BR L","BSD","CA D",
"CHF","CLP","CN Y","CYP","CZK", "DEM","DKK","DZ D","EGP","ES P",
"EUR","FIM","FJ D","FRF","GBP", "GRD","HKD","HU F","IDR","IE P",
"ILS","INR","IS K","ITL","JMD", "JOD","JPY","KR W","LBP","LU F",
"MXN","MYR","NL G","NOK","NZD", "PHP","PKR","PL N","PTE","RO L",
"RUR","SAR","SD D","SEK","SGD", "SKK","THB","TR L","TTD","TW D",
"USD","VEB","XA G","XAU","XCD", "XDR","XPD","XP T","ZAR","ZM K"];
var data =
{
nCol:6,
nRow:10,
nCellWidth:70,
nCellHeight:20
};
data.colHeaders = currencies;
data.rowHeaders = currencies;
data.values = new Array();
for ( var i = 0; i < currencies.leng th; i++ )
{
data.values.pus h(new Array());
for ( var j = 0; j < currencies.leng th; j++ )
{
if ( i == j )
data.values[i].push('-');
else
data.values[i].push(Math.roun d(10000*Math.ra ndom() /
Math.random())/10000);
}
}
new Grid('theGrid', data);
</script>
Full scrolling grid example.
NB: The values in this table bear no relation to any currency, real
or imaginary.
</body>
</html>
This javascript creates a table that has a header and side column that
do not move while scrolling through the table. I need to convert this
to vb script. Can anybody help, or do you have code in vb (asp) that
would do the same thing?
<html>
<head>
<title>Scrollin g Grid Demo</title>
<script type="text/javascript">
function Grid(name, data)
{
// store arguments
this.name = name;
this.data = data;
var cursor = document.all ? "hand" : "pointer";
// persist object for later use.
window[name] = this;
// initialize internal properties.
this.xOffset = 0;
this.yOffset = 0;
// render table
var aStr = new Array;
aStr.push('<tab le border=1 cellpadding=0 cellspacing=0 id="' +
this.name + '">');
// column header row
aStr.push('<tr> ');
aStr.push('<td> </td>');
for ( var j = 0; j < this.data.nCol; j++ )
{
aStr.push('<th width=' + this.data.nCell Width + '><span>' +
this.data.colHe aders[j] + '</span></th>');
}
aStr.push('<td width=20> </td>');
aStr.push('</tr>');
// data rows
for ( var i = 0; i < this.data.nRow; i++ )
{
aStr.push('<tr> ');
aStr.push('<th valign=top width=' + this.data.nCell Width + '><span>'
+ this.data.rowHe aders[i] + '</span></th>');
for ( j = 0; j < this.data.nCol; j++ )
aStr.push('<td> <span style="overflow :hidden;width:' +
this.data.nCell Width + 'px;height:' + this.data.nCell Height + 'px;
text-align:center;"> ' + this.data.value s[i][j] + '</span></td>');
// add the vertical scroll bar
if ( i == 0 )
{
aStr.push('<td rowspan=' + this.data.nRow + ' valign=top>');
aStr.push('<div style="position :relative;heigh t:' + nHeight +
'px;width:20px; ">');
// add the scroll indicator
var nHeight = this.data.nRow * this.data.nCell Height +
(this.data.nRow-1) * 2;
var nStartHeight = 1;
var nBarHeight = Math.floor(nHei ght * this.data.nRow /
this.data.rowHe aders.length);
var nEndHeight = nHeight - nStartHeight - nBarHeight;
aStr.push('<div style="position :absolute;heigh t=120px;">');
aStr.push('<tab le width=20 height=' + nHeight + ' border=0
cellpadding=0 cellspacing=0>' );
aStr.push('<tr> <td height=1><div></div></td></tr>');
aStr.push('<tr> <td height=' + nBarHeight + ' bgcolor="#33cc3 3"
height=20><div> </div></td></tr>');
aStr.push('<tr> <td height=' + nEndHeight +
'><div></div></td></tr>');
aStr.push('</table>');
aStr.push('</div>');
// add the scroll buttons
aStr.push('<div style="position :absolute;heigh t=' + nHeight +
'px;width=20px; ">');
aStr.push('<tab le width=20 height=' + nHeight + ' border=0
cellpadding=0 cellspacing=0>' );
aStr.push('<tr> <td width=' + nHeight/2 + ' valign=top
align=center><d iv style="cursor:' + cursor + ';" onclick="window .' +
this.name + '.scroll(0,-1);">^</div></td></tr>');
aStr.push('<tr> <td width=' + nHeight/2 + ' valign=bottom
align=center><d iv style="cursor:' + cursor + ';" onclick="window .' +
this.name + '.scroll(0,1);" >v</div></td></tr>');
aStr.push('</table>');
aStr.push('</div>');
aStr.push('</div>');
aStr.push('</td>');
}
aStr.push('</tr>');
}
// add the horizontal scroll bar
aStr.push('<tr> ');
aStr.push('<td> </td>');
aStr.push('<td colspan=' + this.data.nCol + '>');
aStr.push('<div style="position :relative;width =' + nWidth +
'px;height=20px ;">');
// the scroll indicator part
var nWidth = this.data.nCol * this.data.nCell Width +
(this.data.nCol-1) * 2;
var nStartWidth = 1;
var nBarWidth = Math.floor(nWid th * this.data.nCol /
this.data.colHe aders.length);
var nEndWidth = nWidth - nStartWidth - nBarWidth;
aStr.push('<div style="position :absolute;width =' + nWidth +
'px;left:0px;to p:0px">');
aStr.push('<tab le width=' + nWidth + ' border=0 cellpadding=0
cellspacing=0>' );
aStr.push('<tr> ');
aStr.push('<td width=1><div></div></td>');
aStr.push('<td width=' + nBarWidth + ' bgcolor="#33cc3 3"
height=20><div> </div></td>');
aStr.push('<td width=' + nEndWidth + '><div></div></td>');
aStr.push('</tr>');
aStr.push('</table>');
aStr.push('</div>');
// the scroll buttons
aStr.push('<div style="position :absolute;width =' + nWidth +
'px;;left:0px;t op:0px">');
aStr.push('<tab le width=' + nWidth + ' border=0 cellpadding=0
cellspacing=0>' );
aStr.push('<tr> ');
aStr.push('<td width=' + nWidth/2 + ' align=left><div style="cursor:'
+ cursor + ';width:20px;" onclick="window .' + this.name +
'.scroll(-1,0);"><</div></td>');
aStr.push('<td width=' + nWidth/2 + ' align=right><di v
style="cursor:' + cursor + ';width:20px;" onclick="window .' +
this.name + '.scroll(1,0);" >></div></td>');
aStr.push('</tr>');
aStr.push('</table>');
aStr.push('</div>');
aStr.push('&nbs p;');
aStr.push('</div>');
aStr.push('</td>');
aStr.push('<td> </td>');
aStr.push('</tr>');
// finally close off the table
aStr.push('</table>');
// write HTML to document.
document.write( aStr.join(''));
}
// locate all spans and control points
Grid.prototype. init = function()
{
// if already initialized, return
if ( this.oTable ) return;
this.oTable = document.getEle mentById(this.n ame);
// get all <span> elements within the table
var aSpan = this.oTable.get ElementsByTagNa me('span');
var n = 0;
// the first few are all column headers
this.aColSpan = new Array;
for ( var j = 0; j < this.data.nCol; j++ )
this.aColSpan.p ush(aSpan[n++]);
// the remainder are row headers and cells
this.aRowSpan = new Array;
this.aCellSpan = new Array;
for ( var i = 0; i < this.data.nRow; i++ )
{
this.aRowSpan.p ush(aSpan[n++]);
this.aCellSpan. push(new Array());
for ( j = 0; j < this.data.nCol; j++ )
this.aCellSpan[i].push(aSpan[n++]);
}
// get all the <div> elements
var aDiv = this.oTable.get ElementsByTagNa me('div');
// the vertical scroll is in aDiv[2]
this.aVerticalT D = aDiv[1].getElementsByT agName('td');
// the horizontal scroll is in aDiv[10]
this.aHorizonta lTD = aDiv[9].getElementsByT agName('td');
}
// fill all the column/row headers and cell values
// and adjust the scroll bars
Grid.prototype. fill = function()
{
this.init();
// headers
for ( var j = 0; j < this.data.nCol; j++ )
this.aColSpan[j].innerHTML = this.data.colHe aders[j + this.xOffset];
for ( var i = 0; i < this.data.nRow; i++ )
this.aRowSpan[i].innerHTML = this.data.rowHe aders[i + this.yOffset];
// values
for ( i = 0; i < this.data.nRow; i++ )
for ( j = 0; j < this.data.nCol; j++ )
this.aCellSpan[i][j].innerHTML = this.data.value s[i +
this.yOffset][j + this.xOffset];
// scroll bars
var nHeight = this.data.nRow * this.data.nCell Height +
(this.data.nRow-1) * 2;
var nStartHeight = Math.floor(nHei ght * this.yOffset /
this.data.rowHe aders.length);
if ( nStartHeight == 0 ) nStartHeight++;
var nBarHeight = Math.floor(nHei ght * this.data.nRow /
this.data.rowHe aders.length);
var nEndHeight = nHeight - nStartHeight - nBarHeight;
if ( nEndHeight == 0 ) nStartHeight--, nEndHeight++;
this.aVerticalT D[0].height = nStartHeight;
this.aVerticalT D[1].height = nBarHeight;
this.aVerticalT D[2].height = nEndHeight;
var nWidth = this.data.nCol * this.data.nCell Width +
(this.data.nCol-1) * 2;
var nStartWidth = Math.floor(nWid th * this.xOffset /
this.data.colHe aders.length);
if ( nStartWidth == 0 ) nStartWidth++;
var nBarWidth = Math.floor(nWid th * this.data.nCol /
this.data.colHe aders.length);
var nEndWidth = nWidth - nStartWidth - nBarWidth;
if ( nEndWidth == 0 ) nEndWidth++, nStartWidth--;
this.aHorizonta lTD[0].width = nStartWidth;
this.aHorizonta lTD[1].width = nBarWidth;
this.aHorizonta lTD[2].width = nEndWidth;
}
Grid.prototype. scroll = function(x,y)
{
this.xOffset += x;
if ( this.xOffset < 0 ) this.xOffset = 0;
if ( this.xOffset > this.data.colHe aders.length - this.data.nCol )
this.xOffset = this.data.colHe aders.length - this.data.nCol;
this.yOffset += y;
if ( this.yOffset < 0 ) this.yOffset = 0;
if ( this.yOffset > this.data.rowHe aders.length - this.data.nRow )
this.yOffset = this.data.rowHe aders.length - this.data.nRow;
this.fill();
}
</script>
</head>
<body>
ggg
<script>
var currencies = ["ARS","ATS","AU D","BBD","BEF", "BGL","BMD","BR L","BSD","CA D",
"CHF","CLP","CN Y","CYP","CZK", "DEM","DKK","DZ D","EGP","ES P",
"EUR","FIM","FJ D","FRF","GBP", "GRD","HKD","HU F","IDR","IE P",
"ILS","INR","IS K","ITL","JMD", "JOD","JPY","KR W","LBP","LU F",
"MXN","MYR","NL G","NOK","NZD", "PHP","PKR","PL N","PTE","RO L",
"RUR","SAR","SD D","SEK","SGD", "SKK","THB","TR L","TTD","TW D",
"USD","VEB","XA G","XAU","XCD", "XDR","XPD","XP T","ZAR","ZM K"];
var data =
{
nCol:6,
nRow:10,
nCellWidth:70,
nCellHeight:20
};
data.colHeaders = currencies;
data.rowHeaders = currencies;
data.values = new Array();
for ( var i = 0; i < currencies.leng th; i++ )
{
data.values.pus h(new Array());
for ( var j = 0; j < currencies.leng th; j++ )
{
if ( i == j )
data.values[i].push('-');
else
data.values[i].push(Math.roun d(10000*Math.ra ndom() /
Math.random())/10000);
}
}
new Grid('theGrid', data);
</script>
Full scrolling grid example.
NB: The values in this table bear no relation to any currency, real
or imaginary.
</body>
</html>
Comment