On the theory this is something you'll have to do repetitively, get the lengths of the longest string in each column (ONCE) to get a ballpark idea of what you need for screen-realestate. Make your peace with a need to sidescroll to see all the columns. And recognize that this is rough and ready; different data sets could make hardcoding this way a total bust (though, of course you could build the length determination function into your program :-) but that could easily overwhelm the speedup.)
Say the results come up this way:
col len
1: 11
2: 4
3: 80
4: 27
In total, you need space for 122 chars per row plus whatever the row label will be (if used). Let's assume no label. So now you can set up your table this way:
<table width="100%"> #other good practices omitted; beyond the scope
+here
<thead>
<tr>
<th style="width: 11em;">Col1</th>
<th style="width: 4em;">Col2</th>
<th style="width: 80em;">Col3</th>
<th style="width: 27em;">Col4</th>
</tr>
</thead>
<tbody>
<tr>
<td (whatever styling you want)...</td>
etc.
The tds will inherit their widths from the ths (unless a td ends up with more chars than expected, in which case, different browsers will react in variant ways).
Hope this helps, but a solid-er answer is probably, "build a better browser."
|