SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2009
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Table row height

    I am trying to find out how many rows can be displayed in a table as the browser is resized. I have a table that does not have a fixed width or height. I am planning to display a scrolling stream in this table by removing one row from the top and adding another one at the bottom of the table so that the display area keeps changeable number of rows that can fit in the display area based on the browser's width and height. If any one has a sample JavaScript for this scenario that will be great.

    Thanks

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2009
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You do not need to reply to my question. I came up with the solution that I needed. If any body needs the same solution, I have the function below.

    function removeTopRow()
    {
    var tbl = document.getElementById('streamtbl');
    var oRows = tbl.getElementsByTagName('tr');

    if (!oRows)
    return;

    var rowCount = oRows.length;
    var tdHeight;

    if (tbl.firstChild && tbl.firstChild.firstChild && tbl.firstChild.firstChild.clientHeight)
    tdHeight = tbl.firstChild.firstChild.clientHeight
    else
    tdHeight = oRows[0].cells[0].clientHeight;

    var prntHeight = tbl.parentNode.clientHeight;

    if (tdHeight && prntHeight && tdHeight > 0 && prntHeight > 0)
    {
    if (Math.round((prntHeight / tdHeight)) <= rowCount)
    {
    tbl.deleteRow(0);
    }
    }
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •