code_junkie

aligning columns in two separate (but related) html tables

Nov 13th, 2011
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. <div style="padding-right:18px"><!-- to account for the scrollbar on the other div -->
  2. <table id="head">
  3. <tr>
  4. <th>Col 1</th>
  5. <th>Col 2</th>
  6. </tr>
  7. </table>
  8. </div>
  9. <div style="height:400px; overflow-y:scroll">
  10. <table id="body">
  11. <tr>
  12. <td>Val 1a</td>
  13. <td>Val 2a</td>
  14. </tr>
  15. <tr>
  16. <td>Val 1b</td>
  17. <td>Val 2b - this cell is wide</td>
  18. </tr>
  19. </table>
  20. </div>
  21.  
  22. dojo.addOnLoad(function(){
  23. var $bodyRow = dojo.query('#body tr')[0];
  24. var $headRow = dojo.query('#head tr')[0];
  25. dojo.forEach($bodyRow.cells, function(item, index){
  26. var w = item.offsetWidth;
  27. dojo.style($headRow.cells[index], 'width', w + "px");
  28. });
  29. });
  30.  
  31. dojo.addOnLoad(function(){
  32. var $bodyRow = dojo.query('#body tr')[0];
  33. var $headRow = dojo.query('#head tr')[0];
  34. dojo.forEach($bodyRow.cells, function(item, index){
  35. var w = dojo.style($bodyRow.cells[index], 'width');
  36. dojo.style($headRow.cells[index], 'width', w + "px");
  37. });
  38. });
  39.  
  40. th, td { width: 50%; } // get 2 equal width columns in both tables
Add Comment
Please, Sign In to add comment