Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7667239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:03:05+00:00 2026-05-31T15:03:05+00:00

UPDATE: Solution found UPDATE: No proposed answers. No solution found on my end. Anybody?

  • 0

UPDATE: Solution found

UPDATE: No proposed answers. No solution found on my end. Anybody?

I am using javascript to match the width of columns in two seperate tables (using this to create a scrollable, sticky header table. If the data is all visible (no overflow), the method works fine. If the tables do overflow, however, the table columns do not align. I have a debugging stream that shows the offsetWidths are still returning the same numbers. Any ideas on why this is happening?

Main HTML:

<link rel="stylesheet" type="text/css" href="CSS/APTEIT.css"/>
<script type="text/javascript" src="Utilities/Javascript/Utilities.js"></script>
<script type="text/javascript" src="Utilities/Javascript/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    HtmlLoggerControlInstance.getInstance().setLevel("debug",HtmlLogger.ALL);
    syncColumnWidths("headers",null,"data",null);
});
</script>
<html>
    <head>
        <title>APTEIT</title>
    </head>
    <body>
        <!--#include file="Utilities/Debug.aspx"-->
        <img src="Images/logo.png" />
        <div id="headersDiv">
            <table class="tbl" id="headers">
                <tr>
                    <td>head1</td>
                    <td>head2reallyreallylong</td>
                    <td>hd3</td>
                    <td>4</td>
                </tr>
            </table>
        </div>
        <div id="dataDiv" onscroll="syncScrolling('dataDiv','headersDiv');">
            <table class="tbl" id="data">
            <tr>
                <td>alsdja;lksdjaljkdf</td>
                <td>kdki</td>
                <td>k39</td>
                <td>lsjdl</td>
            </tr>
            <tr>
                <td>alsdja;lksdjaljkdf</td>
                <td>kdki</td>
                <td>k39</td>
                <td>lsjdl</td>
            </tr><tr>
                <td>alsdja;lksdjaljkdasdfaf</td>
                <td>kdki</td>
                <td>k39</td>
                <td>lsjdl</td>
            </tr><tr>
                <td>alsdja;lksdjaljkdf</td>
                <td>kdki</td>
                <td>k39</td>
                <td>lsjdl</td>
            </tr><tr>
                <td>alsdja;lksdjaljkdfs</td>
                <td>kdki</td>
                <td>k39</td>
                <td>lsjdl</td>
            </tr><tr>
                <td>alsdf</td>
                <td>kdki</td>
                <td>k39</td>
                <td>lsjdl</td>
            </tr>
            </table>
        </div>
    </body>
</html>

Javascript Method:

/*
Syncs column sizes between two tables. 

@param string table1 : First table to sync
@param int table1HeadRow : Row to use as column width sync for table1 (if null, uses first row)
@param string table2 : Second table to sync
@param int table2HeadRow : Row to use as column width sync for table2 (if null, uses first row)
*/
function syncColumnWidths(table1, table1HeadRow ,table2, table2HeadRow){
    UtilLogger.log(HtmlLogger.INFO,"-Syncing Column Widths-")
    if((typeof table1 == "string" ||table1.constructor == String) && (typeof table2 == "string" ||table2.constructor == String)
        && (typeof table1HeadRow == "number" || table1HeadRow == null) && (typeof table2HeadRow == "number" || table1HeadRow == null)){
        tableOne = document.getElementById(table1);
        tableTwo = document.getElementById(table2);

        //Set row to check and get row
        if(table1HeadRow == null){
            t1Start = 0;
        }
        else{
            t1Start = table1HeadRow;
        }
        if(table2HeadRow == null){
            t2Start = 0;
        }
        else{
            t2Start = table2HeadRow;
        }
        t1Row = tableOne.rows[t1Start];
        t2Row = tableTwo.rows[t2Start];

        //Get end number
        if(t1Row.cells.length < t2Row.cells.length){
            tEnd = t1Row.cells.length;
        }
        else{
            tEnd = t2Row.cells.length;
        }

        //Sync widths
        for(i = 0; i < tEnd; i++){
            UtilLogger.log(HtmlLogger.CONFIG,"syncColumnWidths:t1 width:"+t1Row.cells[i].offsetWidth+"   t2 width:"+t2Row.cells[i].offsetWidth);
            if(t1Row.cells[i].offsetWidth > t2Row.cells[i].offsetWidth){
                t2Row.cells[i].style.width = t1Row.cells[i].offsetWidth+"px";
                t1Row.cells[i].style.width = t1Row.cells[i].offsetWidth+"px";
                UtilLogger.log(HtmlLogger.FINE,"syncColumnWidths:setting t2 width to t1");
            }
            else{
                t1Row.cells[i].style.width = t2Row.cells[i].offsetWidth+"px";
                t2Row.cells[i].style.width = t2Row.cells[i].offsetWidth+"px";
                UtilLogger.log(HtmlLogger.FINE,"syncColumnWidths:setting t1 width to t2");
            }
        }

    }
    else{
        alert("syncColumnWidths takes parameters (string, int|null, string, int|null)");
    }
    UtilLogger.log(HtmlLogger.INFO,"-Syncing Column Widths Complete-");
}

CSS:

.tbl{
border-collapse:collapse;
}
.tbl tr td{
border-width:1px;
border-color:black;
border-style:solid;
}

#headersDiv{
max-width:100px;
overflow:hidden;
}

#dataDiv{
max-width:100px;
overflow:auto;
}

Debug prints:

-Syncing Column Widths Complete-
syncColumnwidths:t1 style width:28px t2 style width:28px
syncColumnWidths:setting t1 width to t2
syncColumnWidths:t1 width:12 t2 width:28
syncColumnwidths:t1 style width:27px t2 style width:27px
syncColumnWidths:setting t1 width to t2
syncColumnWidths:t1 width:26 t2 width:27
syncColumnwidths:t1 style width:129px t2 style width:129px
syncColumnWidths:setting t2 width to t1
syncColumnWidths:t1 width:129 t2 width:30
syncColumnwidths:t1 style width:137px t2 style width:137px
syncColumnWidths:setting t1 width to t2
syncColumnWidths:t1 width:40 t2 width:137
-Syncing Column Widths-
-Default Page Loaded-
-Default Page Loading-
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:03:06+00:00Added an answer on May 31, 2026 at 3:03 pm

    Table-layout for both tables needs to be fixed in order to adjust the size of the cells and have it affect the table as a whole. By default, this is auto, and the table adjusts to the size of it’s container/contents of its cells.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: We are still using XP at work and I got my solution working,
UPDATE: Focus your answers on hardware solutions please. What hardware/tools/add-in are you using to
I am not interested in any auto update solution, such as ClickOnce or the
NOTE: I added my new solution at the UPDATE answer below. I try to
Update: This question was an epic failure, but here's the working solution. It's based
Update: giving a much more thorough example. The first two solutions offered were right
Update 3/4: I've done some testing and proved that using checkout event handler to
EDIT: I found a solution for this, you can read it in my answer
Solution found, see my comment below D5, odbc to mysql database This code: with
Original Question mysql-server-6.0.10 I have this problem, I'm using the COMPRESS function to update

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.