Results 1 to 8 of 8

Thread: JavaScript getClientRects() does not work in Content Page

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    JavaScript getClientRects() does not work in Content Page

    I have a aspx page with a table with scrollable rows.
    I achived this by having a "header" table, and a "rows" table. The rows table has a div with "overflow:auto" so get the scroll bar.

    When data is loaded in the rows table, the columns have diferent sizes, and since the columns are not fixed width, the header columns don't match with rows columns.

    To fix this, using JavaScript, I loop through the first row in the "rows" table, and I call the getClientRects() function to get the cell bownds, calculate the column width and assign that value to the header table columns.

    This works perfectly when I use a regular aspx page. I decided to switch to a master-content achitecture, because I have a tab menu at the top of the page, and I copied and pasted the code into the content page.

    Everything works fine, but the getClientRects() returns all values as 0 (zeros).


    So how can I get the getClientRects() to return the propper values ?



    Here is the relevant code:
    ASP Code:
    1. <script language="JavaScript" type="text/javascript">
    2.     function SetTableColWidth() {
    3.         var th = document.getElementById("tbl_SearchResult_Header");
    4.         var tr = document.getElementById("tbl_SearchResult_Rows");
    5.  
    6.         if (tr != null) {
    7.             if (tr.rows.length > 0) {
    8.                 for (i = 0; i < 7; i++) {
    9.                     rcts = tr.rows[0].children[i].getClientRects();
    10.                     th.rows[1].children[i].style.width = (rcts[0].right - rcts[0].left) + "px";
    11.                 }
    12.  
    13.                 for (i = 0; i < 7; i++) {
    14.                     rcts = th.rows[1].children[i].getClientRects();
    15.                     tr.rows[0].children[i].style.width = (rcts[0].right - rcts[0].left) + "px";
    16.                 }
    17.             }
    18.         }
    19.     }
    20. </script>
    21.  
    22.  
    23. <table id="tbl_SearchResult_Header" cellpadding="2" cellspacing="1" width="750px" style="background: #99B4F1; padding: 0px; border-style: solid solid none solid; border-width: 2px; border-color: #000000">
    24. <tr class="SectionTableTitle">
    25.     <td colspan="7">Search results</td>
    26. </tr>
    27. <tr class="SectionTableTitle">
    28.     <td>aaaaaaaaaa</td>
    29.     <td>aaaaaaaaaa</td>
    30.     <td>aaaaaaaaaa</td>
    31.     <td>aaaaaaaaaa</td>
    32.     <td>aaaaaaaaaa</td>
    33.     <td>aaaaaaaaaa</td>
    34.     <td>aaaaaaaaaa</td>
    35. </tr>
    36. </table>
    37. <div style="width:770px;height:255px;overflow:auto;">
    38. <asp:Repeater ID="rptSearchResults" runat="server">
    39. <HeaderTemplate>
    40.     <table id="tbl_SearchResult_Rows" cellpadding="2" cellspacing="1" width="750px" style="background: #99B4F1; padding: 0px; border-style: none solid solid solid; border-width: 2px; border-color: #000000">
    41. </HeaderTemplate>
    42. <ItemTemplate>
    43.     <tr align="left" bgcolor='#E0E0E0'
    44.             onmouseover="this.bgColor='#C8C8C8'" onmouseout="this.bgColor='#E0E0E0'"
    45.             onclick="SubmitChoice(<%#Container.DataItem("aaaaaaaaaa_ID")%>);" style="cursor:pointer;">
    46.         <td><%#Container.DataItem("aaaaaaaaaa")%></td>
    47.         <td><%#Container.DataItem("aaaaaaaaaa")%></td>
    48.         <td><%#Container.DataItem("aaaaaaaaaa")%></td>
    49.         <td><%#Container.DataItem("aaaaaaaaaa")%></td>
    50.         <td><%#Container.DataItem("aaaaaaaaaa")%></td>
    51.         <td><%#Container.DataItem("aaaaaaaaaa")%></td>
    52.         <td align="center"><%#Container.DataItem("aaaaaaaaaa")%></td>
    53.     </tr>
    54. </ItemTemplate>
    55. <AlternatingItemTemplate>
    56.     <tr align="left" bgcolor='#F0F0F0'
    57.             onmouseover="this.bgColor='#C8C8C8'" onmouseout="this.bgColor='#F0F0F0'"
    58.             onclick="SubmitChoice(<%#Container.DataItem("aaaaaaaaaa_ID")%>);" style="cursor:pointer;">
    59.         <td><%#Container.DataItem("aaaaaaaaaa")%></td>
    60.         <td><%#Container.DataItem("aaaaaaaaaa")%></td>
    61.         <td><%#Container.DataItem("aaaaaaaaaa")%></td>
    62.         <td><%#Container.DataItem("aaaaaaaaaa")%></td>
    63.         <td><%#Container.DataItem("aaaaaaaaaa")%></td>
    64.         <td><%#Container.DataItem("aaaaaaaaaa")%></td>
    65.         <td align="center"><%#Container.DataItem("aaaaaaaaaa")%></td>
    66.     </tr>
    67. </AlternatingItemTemplate>
    68. <FooterTemplate>
    69.     </table>
    70. </FooterTemplate>
    71. </asp:Repeater>
    72. </div>
    73.  
    74.  
    75. <script language="JavaScript" type="text/javascript">
    76.         SetTableColWidth();
    77. </script>

    I attached an image to get an idea how it looks (when it works)
    Attached Images Attached Images  

Posting Permissions

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



Click Here to Expand Forum to Full Width