tags:

views:

36

answers:

2

Hi All,

I have a table which shows records from DB dynamically. I just need to fix the height of the table, so that the table gets a scrolling window downwards within the table itself if it has large number of rows. This is so the user wont need to scroll the entire page?

Is this possible...?

Thanks in advance...

A: 

can be done with css http://websitetips.com/articles/css/scrollbars/

Grumpy
@Grumpy, ie for textarea, not for tables..
soorajthomas
+1  A: 

One solution to this would be to use a <div>-layer surrounding the <table>, where you use the style-attribute with: overflow: auto; max-height: (whatever height you want here)

As an example:

<div id="mainHolder" style="overflow: auto; max-height: 400px;">
    <table>
    ... Lots of data ...
    </table>
</div>

This would create a table that can grow in height, but it would be restrained in the div-layer, and you would automatically get scrollbars when the content grows larger than 400px.

With jQuery you can also do something like this:

<script type="text/javascript">
window.onresize = doResize;

function doResize() {
    var h = (typeof window.innerHeight != 'undefined' ? window.innerHeight : document.documentElement.clientHeight) - 20;
    $('#mainHolder').css('max-height', h);
    $('#mainHolder').css('height', h);
};

$(document).ready(function () { doResize(); });
</script>
NoLifeKing
Good solution, but note that max-height doesn't work in older versions of Explorer, so if you need to support IE6, you'll need to do additional hacking.
Spudley
Internet Explorer 6 will soon be out of the market anyway. Otherwise, it really should be. Sure, I also am a fan of cross browser-things, but I would like the browsers to support standard-css aswell. And IE6 is such an old browser, it shouldn't be considered.
NoLifeKing
My bad luck, my clients are working with IE6...so what will I do...any other tips for above
soorajthomas
This link shows how you could solve the IE6-problem http://www.visibilityinherit.com/code/ie6-min-max-height-width.php
NoLifeKing
i will check it, thanks a lot NoLifeKing
soorajthomas
Great it worked like a charm in IE6, This forum is GREAT
soorajthomas