Making a table column auto-resize

Reply

Join Date: Nov 2004
Posts: 4
Reputation: Egsal is an unknown quantity at this point 
Solved Threads: 0
Egsal Egsal is offline Offline
Newbie Poster

Making a table column auto-resize

 
0
  #1
Nov 22nd, 2004
I'm working on a website for my friend and we're having some problems. We have set up a table to handle the main page, which has within the table a shoutbox, news posts, and links. The news bits within the table are (obviously) longer in terms of space used up than the other bits on the table. So what I did was use the rowspan argument to increase the amount of space that the news feed takes up, but that really isn't enough room, since when we add more news we'll run low on room. Now I would assume that the table would auto-resize to accomidate the length of the news feed, and it does. The problem is that it seems to auto-resize the shoutbox and the first box on the links list as well. Also annoying is the fact that the news is centered both horizontally and vertically, and I would like to center it horizontally only. Both of these are interconnected, because before I resized the news stuff everything worked perfectly, but after I did the problems began coming up. What can I do?
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 764
Reputation: DaveSW is on a distinguished road 
Solved Threads: 17
DaveSW's Avatar
DaveSW DaveSW is offline Offline
Master Poster

Re: Making a table column auto-resize

 
0
  #2
Nov 23rd, 2004
Personally I use css not tables for layout, but similar principles apply.
Because you can't say how big a persons screen will be, there is no one no. of pixels that can be defined as the screen width. Hence if you set the width of the side columns in pixels you can allow the center column to expand without altering the width of the others.
Does that help you at all? if not then you might want to show us the page you're working on - upload or zip.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 16
Reputation: vee_liang is an unknown quantity at this point 
Solved Threads: 1
vee_liang vee_liang is offline Offline
Newbie Poster

Re: Making a table column auto-resize

 
0
  #3
Dec 11th, 2008
maybe you can try this one. hope it helps

add to your HTML command:
HTML and CSS Syntax (Toggle Plain Text)
  1. <script type="text/javascript" language="javascript1.2">installTable(tableID);</script>

Javascript:
  1.  
  2. var markerHTML = "<>";
  3. var minWidth = 100;
  4. var dragingColumn = null;
  5. var startingX = 0;
  6. var currentX = 0;
  7.  
  8. function getNewWidth () {
  9. var newWidth = minWidth;
  10. if (dragingColumn != null) {
  11. newWidth = parseInt (dragingColumn.parentNode.style.width);
  12. if (isNaN (newWidth)) {
  13. newWidth = 0;
  14. }
  15. newWidth += currentX - startingX;
  16. if (newWidth < minWidth) {
  17. newWidth = minWidth;
  18. }
  19. }
  20. return newWidth;
  21. }
  22.  
  23. function columnMouseDown (event) {
  24. if (!event) {
  25. event = window.event;
  26. }
  27. if (dragingColumn != null) {
  28. ColumnGrabberMouseUp ();
  29. }
  30. startingX = event.clientX;
  31. currentX = startingX;
  32. dragingColumn = this;
  33. return true;
  34. }
  35.  
  36. function columnMouseUp () {
  37. if (dragingColumn != null) {
  38. dragingColumn.parentNode.style.width = getNewWidth ();
  39. dragingColumn = null;
  40. }
  41. return true;
  42. }
  43.  
  44. function columnMouseMove (event) {
  45. if (!event) {
  46. event = window.event;
  47. }
  48. if (dragingColumn != null) {
  49. currentX = event.clientX;
  50. dragingColumn.parentNode.style.width = getNewWidth ();
  51. startingX = event.clientX;
  52. currentX = startingX;
  53. }
  54. return true;
  55. }
  56.  
  57. function installTable (tableId) {
  58. var table = document.getElementById (tableId);
  59. // Test if there is such element in the document
  60. if (table != null) {
  61. // Test is this element a table
  62. if (table.nodeName.toUpperCase () == "TABLE") {
  63. document.body.onmouseup = columnMouseUp;
  64. document.body.onmousemove = columnMouseMove;
  65. for (i = 0; i < table.childNodes.length; i++) {
  66. var tableHead = table.childNodes[i];
  67. // Look for the header
  68. // Tables without header will not be handled.
  69. if (tableHead.nodeName.toUpperCase () == "THEAD") {
  70. // Go through THEAD nodes and set resize markers
  71. // IE in THEAD contains TR element which contains TH elements
  72. // Mozilla in THEAD contains TH elements
  73. for (j = 0; j < tableHead.childNodes.length; j++) {
  74. var tableHeadNode = tableHead.childNodes[j];
  75. // Handles IE style THEAD with TR
  76. if (tableHeadNode.nodeName.toUpperCase () == "TR") {
  77. for (k = 0; k < tableHeadNode.childNodes.length; k++) {
  78. var column = tableHeadNode.childNodes[k];
  79. var marker = document.createElement ("span");
  80. marker.innerHTML = markerHTML;
  81. marker.style.cursor = "move";
  82. marker.onmousedown = columnMouseDown;
  83. column.appendChild (marker);
  84. if (column.offsetWidth < minWidth) {
  85. column.style.width = minWidth;
  86. }
  87. else {
  88. column.style.width = column.offsetWidth;
  89. }
  90. }
  91. }
  92. // Handles Mozilla style THEAD
  93. else if (tableHeadNode.nodeName.toUpperCase () == "TH") {
  94. var column = tableHeadNode;
  95. var marker = document.createElement ("span");
  96. marker.innerHTML = markerHTML;
  97. marker.style.cursor = "move";
  98. marker.onmousedown = columnMouseDown;
  99. column.appendChild (marker);
  100. if (column.offsetWidth < minWidth) {
  101. column.style.width = minWidth;
  102. }
  103. else {
  104. column.style.width = column.offsetWidth;
  105. }
  106. }
  107. }
  108. table.style.tableLayout = "fixed";
  109. // Once we have found THEAD element and updated it
  110. // there is no need to go through rest of the table
  111. i = table.childNodes.length;
  112. }
  113. }
  114. }
  115. }
  116. }

-- uos...wrong thread...sorry
Last edited by vee_liang; Dec 11th, 2008 at 4:53 am.
Vee Liang
To be right, first you have to know what wrong is.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,210
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 164
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: Making a table column auto-resize

 
0
  #4
Dec 15th, 2008
Originally Posted by Egsal View Post
I'm working on a website for my friend and we're having some problems. We have set up a table to handle the main page, which has within the table a shoutbox, news posts, and links. The news bits within the table are (obviously) longer in terms of space used up than the other bits on the table. So what I did was use the rowspan argument to increase the amount of space that the news feed takes up, but that really isn't enough room, since when we add more news we'll run low on room. Now I would assume that the table would auto-resize to accomidate the length of the news feed, and it does. The problem is that it seems to auto-resize the shoutbox and the first box on the links list as well. Also annoying is the fact that the news is centered both horizontally and vertically, and I would like to center it horizontally only. Both of these are interconnected, because before I resized the news stuff everything worked perfectly, but after I did the problems began coming up. What can I do?
Use the vertical-align: top; style. This moves all of the text in each cell to the top.I always include that style with a table, because IE and FF do different things by default.

When you use rowspan or colspan, how the rows and columns are divided without any styles controlling them depends on the relative sizes of the contents. So if you have a rowspan of 2 in the second column, content in the top cells of columns 1 and 3, but nothing in the second rows of columns 1 and 3, the top cells in those columns will be taller.

Don't use pixels to define sizes. This locks you in to one screen resolution. Use points or percent instead.
Last edited by MidiMagic; Dec 15th, 2008 at 2:11 am.
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for HTML and CSS
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC