944,117 Members | Top Members by Rank

Ad:
Nov 22nd, 2004
0

Making a table column auto-resize

Expand 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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Egsal is offline Offline
4 posts
since Nov 2004
Nov 23rd, 2004
0

Re: Making a table column auto-resize

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.
Reputation Points: 54
Solved Threads: 20
Master Poster
DaveSW is offline Offline
765 posts
since Jul 2004
Dec 11th, 2008
0

Re: Making a table column auto-resize

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:
javascript Syntax (Toggle Plain Text)
  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.
Reputation Points: 25
Solved Threads: 8
Light Poster
vee_liang is offline Offline
38 posts
since Aug 2008
Dec 15th, 2008
0

Re: Making a table column auto-resize

Click to Expand / Collapse  Quote originally posted by Egsal ...
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.
Reputation Points: 730
Solved Threads: 181
Nearly a Senior Poster
MidiMagic is offline Offline
3,314 posts
since Jan 2007
Nov 4th, 2011
0
Re: Making a table column auto-resize
i want column auto resize with data added in core java not in web applications
Reputation Points: 19
Solved Threads: 0
Light Poster
Pravinrasal is offline Offline
45 posts
since Jul 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in HTML and CSS Forum Timeline: SELECTED in drop down
Next Thread in HTML and CSS Forum Timeline: Drupal with Zen, advice needed on styling background for active navigation links





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC