codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  scrolling table  jmirickhai at 19:21 on Tuesday, October 19, 2004
 

I'm trying to make a scrollable table where the data scrolls but the headers do not. I pretty much have it working (the code is below). However I'm having one small problem... I need the vertical scroll bar to show always. Right now you have to scroll to the right to see the vertical scroll bar.

If that didnt make any sense just paste the code below. I want to be able to scroll my data without having to scroll all the way to the right first to get the scroll bar.

===================================================

<html>
<head>
<style>
#tableHeader {
position: absolute;
}
#tableData {
position: absolute;
}
</style>
</head>

<body>

<div style="position:absolute; left:0px; top:0px; width:1400px; height:30px; background-color: #999999; layer-background-color: #999999; border: 1px none #000000;">
<table border="1" cellpadding="2" cellspacing="0" bordercolor="#000000" id="tableHeader">
<tr>
<td width="200">HEADER 1</td>
<td width="100">HEADER 2</td>
<td width="200">HEADER 3</td>
<td width="100">HEADER 4</td>
<td width="200">HEADER 5</td>
<td width="100">HEADER 6</td>
<td width="500">HEADER 7</td>
</tr>
</table>
</div>
<div style="position:absolute; left:0px; top:30px; width:1420px; height:100px; background-color: #CCCCCC; layer-background-color: #CCCCCC; border: 1px none #000000;overflow=scroll">
<table border="1" cellpadding="2" cellspacing="0" bordercolor="#000000" id="tableHeader">
<tr>
<td width="200">data</td>
<td width="100">data</td>
<td width="200">data</td>
<td width="100">data</td>
<td width="200">data</td>
<td width="100">data</td>
<td width="500">data</td>
</tr>

<tr>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
</tr>
<tr>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
</tr>
<tr>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
</tr>
<tr>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
</tr>
</table>
</div>
</body>
</html>

  Re: scrolling table  Troy Wolf at 02:53 on Wednesday, October 20, 2004
 

You do realize the only reason you have to scroll right is because you have set your columns widths to a total of 1400 pixels which means that unless your screen resolutions is greater than 1400, you'll have to scroll right.

Assuming you knew that...so are you wanting the vertical scroll bar to float over the table at the right of the screen regardless of the actual right edge of your table? That would look odd, and would not be what any user would expect. I think users would expect to have to scroll to the right edge of the table to find the scroll bar.
Troy Wolf: site expert
Shiny Solutions


  Re: scrolling table  jmirickhai at 15:05 on Wednesday, October 20, 2004
 

yes I realize that it only scrolls because of being 1400 wide. Obvisouly, I disagree that it would look odd... I feel that it would be more useful to the user than making them scroll to see the scroll bar.

check out...
http://jzeil2.100free.com/test.htm

Basicly I want that... but i want the header to be always at the top of the table (cause once the user scrolls down they will still want to know what the columns are).



  Re: scrolling table  Troy Wolf at 18:22 on Wednesday, October 20, 2004
 

After looking at this more, you are right, this is not an add thing, and is in fact exactly what most people would want. The scrolling properties you describe are what people expect in a windows application. There are several component vendors offering solutions to do exactly this and more, but they require server-side installation. If that's an option, it is probably worth the money.

I tried hacking my own, and I got it to work in IE, but in Firefox/Mozilla, it isn't right. I had to work some DHTML magic to resize the data div as the header div scrolls.
<html>
<head>
<style>
</style>
<script language=javascript1.2>
var headDiv, dataDiv;
var scrollTimer, initScroll = 0, lastScroll = 0;
var scrollingActive = false;
function ScrollCapture() {
curScroll = headDiv.scrollLeft;
scrollDiff = curScroll - lastScroll;
if (scrollDiff == 0) {
clearTimeout(scrollTimer);
x = dataDiv.style.width.replace("px","")/1;
x += curScroll - initScroll;
dataDiv.style.width = x+"px";
initScroll = curScroll;
scrollingActive = false;
}
lastScroll = curScroll;
}
function ScrollTrigger() {
if(!scrollingActive) {
scrollingActive = true;
scrollTimer = setInterval('ScrollCapture()',100);
}
}
function LoadTrigger() {
headDiv = document.getElementById('tblHead');
dataDiv = document.getElementById('tblData');
}
window.onload = LoadTrigger;
</script>
</head>

<body>

<div id="tblHead" style="width:800px; background-color:#999999; layer-background-color:#999999; border:1px none #000000; overflow-x:auto;" onscroll="ScrollTrigger();">
<table border="1" cellpadding="2" cellspacing="0" bordercolor="#000000" id="tableHeader">
<tr>
<td width=200 NOWRAP>HEADER 1</td>
<td width=100 NOWRAP>HEADER 2</td>
<td width=200 NOWRAP>HEADER 3</td>
<td width=100 NOWRAP>HEADER 4</td>
<td width=200 NOWRAP>HEADER 5</td>
<td width=100 NOWRAP>HEADER 6</td>
<td width=500 NOWRAP>HEADER 7</td>
</tr>
</table>
<div id="tblData" style="width:800px; height:100px; background-color:#CCCCCC; layer-background-color:#CCCCCC; border:1px none #000000; overflow:auto;">
<table border="1" cellpadding="2" cellspacing="0" bordercolor="#000000" id="tableHeader">
<tr>
<td width=200 NOWRAP>data</td>
<td width=100 NOWRAP>data</td>
<td width=200 NOWRAP>data</td>
<td width=100 NOWRAP>data</td>
<td width=200 NOWRAP>data</td>
<td width=100 NOWRAP>data</td>
<td width=500 NOWRAP>data</td>
</tr>
<tr>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
</tr>
<tr>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
</tr>
<tr>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
</tr>
<tr>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
<td>data</td>
</tr>
</table>
</div>
</div>
</body>
</html>
Troy Wolf: site expert
Shiny Solutions


  Re: scrolling table  jmirickhai at 19:00 on Wednesday, October 20, 2004
 

Cool....

I had come up with a different solution but with the same problems (I cant seem to get it to work in Netscape yet).

I used an iframe instead of resizing the div. I was able to set the position of the header with css but like i said this doesnt seem to work in netscape.

take a look if you are interested

http://jzeil2.100free.com/fdfs.html

  Re: scrolling table  Troy Wolf at 01:37 on Thursday, October 21, 2004
 

Your latest solution inspired me, and I think I got it! Check this out--it works in IE and Firefox 1.0PR

http://www.shinysolutions.com/lib/code/scrollingtable.htm

Of course I'm sure it can be improved, but seems to work well.
Troy Wolf: site expert
Shiny Solutions


  Re: scrolling table  Yusairi at 09:38 on Thursday, October 21, 2004
 

hi troy,

you had given me some sort of idea on how to use
style...

cursor:hand;

thanks a lot.


  Re: scrolling table  jmirickhai at 15:33 on Thursday, October 21, 2004
 

Hey thanks.... I had gotten it working yesterday but your solution is a bit nicer.









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: posting values from pop up window to parent window
•  Testing file for type of data
•  Running VB6 application as a ASP.NET application
•  login system with asp.net
•  Re: Help: Trouble with z-Index and SELECT lists
•  What is wrong with this ASP codes? It don`t seem to work???
•  Need help with ListBox control
•  Re: Good Javascript/DHTML Reference
•  Re: scrolling table


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2004