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...
The height of rows 'tr' in a table can be fixed very easily. This can be done by adding the height attribute in the tr tag. If the height is not specified, the height of the row changes according to the content. The height can be specified either in pixels, or percentage.
To set the row height to a specific measurement, click a cell in the row that you want to resize. On the Layout tab, in the Cell Size group, click in the Table Row Height box, and then specify the height you want. To use the ruler, select a cell in the table, and then drag the markers on the ruler.
Simply add style="line-height:0" to each cell. This works in IE because it sets the line-height of both existant and non-existant text to about 19px and that forces the cells to expand vertically in most versions of IE.
To set the table width in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <table> tag, with the CSS property width.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With