views:

937

answers:

15

The obvious answer to this is "it's not possible" or "make the data smaller"...I have tried these and they don't wash so I need to come up with an alternative

There is a table on a web page that has 14 columns in it. 2 of the columns have text in that is quite long (but cannot wrap - the text must be all on one line for each row). Needless to say, the table disappears off the right hand side of the screen after about column 9!

So, can aanyone think of a magical solution that will make this table fit fully onto the screen?

Bad Answers:

  • Reduce the amount of data
  • Allow the text in the rows to wrap onto a second line
  • "It can't be done" - yes I know, but someone somewhere will have a genius answer, or some magical jQuery library that does this kind of thing

Intriguing but more information would be needed:

  • Squish all of the columns down enough so the table fits, and then have overflowed data which can be viewed when the column is expanded

    eg: |This is my data but it's...|

+5  A: 

Show each logical row in two actual rows, making them clearly coherent using zebra stripes?

I can imagine situations where that would work, but it's highly dependent on the data.

Jon Skeet
How would this work? Showing a row on two rows would just get confusing would it not?
Paul
Zebras help with confusion, or add stronger borders around each logical row.
svinto
(Make a Outlook window small in width to see an example of this.)
svinto
What defines a "logical row"? Each row contains 14 columns, so wrapping columns underneath each other will just make it confusing as to which column heading applies to which piece of data...
Paul
But the question clearly said 'the text must be all on one line for each row'
pavium
@IP: Headings could be in two rows in the same way, with zebra stripes. As you said, there's no perfect solution to your problem, but this one is worth considering.
Argalatyr
it would all be on one row... one big fat row with 2 or more sub-rows!
nickf
I'm not sure it is sorry, the data needs to be on one line, there was to be no wrapping
Paul
+1  A: 

Place table in div with overload:scroll. You'll get horisontal scrollbars, but table will look as supposed. Example:

<div style="width:100%;overflow:scroll;">
<table>...</table>
</div>
Veton
Sorry, yes, this one had been thought of but was also ruled out as it would look odd (apparently) (+1 anyway!)
Paul
A: 

I'd split and zebra as per Jon's suggestion together with your own, cutting off and displaying .... When the user hovers a cut of column, you could show a full width box a bit down with the complete contents. Clicking when the box is showing makes it not go away when moving the mouse to another column, so that the users can copy/paste etcetera.

svinto
+15  A: 
Workshop Alex
+1 just what I was thinking as well...
peirix
Great ... idea ... Alex.
MusiGenesis
This one I like, but unfortunately doesn't work in the case where someone comes along and decides to put 100 columns in (yes, this is what I'm contending with). I will add it to the list of options though, it may still come out as the better of all of the bad options
Paul
Ok, pedantic comment here but this is an ellipsis: … and this is three dots: ... An ellipsis is one character (I was once pulled up on this by a screen reader user who objected to having "dot dot dot" read out all the time.) (On windows use Alt+0133 for an ellipsis.)
edeverett
@edeverett: we respect pedantry around here. :)
MusiGenesis
… is the ellipsis entity.
cpharmston
… or ... Hmmm. Big difference indeed. :-)
Workshop Alex
What if you need to copy and paste from a cell or multiple cells in a row?
Russ Cam
@IP: yep, this _really_ won't work if someone puts in 1000 columns. Point is, effective programmers help those making spec understand the implications of what they're requesting. When preposterous, it's worth backing up to understand **goals** and help them with a spec that helps achieve those goals.
Argalatyr
If your users are using Internet Explorer then it might be possible to rorate the texts in the cells, although I wouldn't know how to do this through CSS. I just know it's possible since I've seen reports in IE with text rotated 90 degrees.
Workshop Alex
A: 

Try to implement tooltip control for those columns that contains large amount of text. For example show just first 100 characters, then insert some nice looking icon on the end of the row, that will pop up, also a nice looking tooltip that contains full text for that column. There are nice jQuery tooltips that will do your job. This implementation will not ruin the look-and-feel of your page, and it's quite flexible in terms of ow much text will you show in the tooltip.

ZokiManas
+1  A: 

Try this as a CSS workaround. You can play with the overflow and word-wrap properties to get the desired result.

table { 
table-layout:fixed; 
width:100%; 
overflow:scroll; 
border:1px solid #f00; 
word-wrap:none; 
}
Bjorn Bailleul
Sorry, definitely no word-wrapping...
Paul
Ok, for the downvote I will give you this:Change word-wrap to normal and set overflow to scroll and it should be ok.
Bjorn Bailleul
A: 

For the nowrap columns you could set them up so the text inside is contained in a div that goes to absolute position and expands to needed width when hovered over.

You could also use jqgrid subgrid

You could just the jquery ui dialog for the onclick event of a row and have some of your data in there.

Stephen lacy
+4  A: 

You could use a horizontal accordion on the table if only one column in a row needs to be expanded at a time. Or, you could do something like this answer (or even this). In the demo, click on a table header to see the result.

Russ Cam
A: 

You can have the text broken into multiple lines and it still comes out as one when cut or copied. Use wbr (word break) tag.

Marko
Sorry, no word-wrapping at all. It wouldn't be very useful only wrapping when it was copied...
Paul
A: 

If I were in your position i'd consider rendering the table in an iframe. This way you could easily have the full table the size you want it, the user would have to scroll to see those columns. It is possible to attach a keyPress event to the iframe and hook those keypresses to scroll if you think it would make it easier for users.

The second option I can think of is to make all the cells a bit narrower such that there is a little spare space on the edge of the screen. Add a class to each element of the table stating which row it is in (this makes it easier to reference them together). Attach a click event to the table and use event.target to get the cell clicked on (this will eat less browser memory than attaching event to each cell). That click event will then expand the width of that column to display all the data and add a class label to the corresponding cell in the first row. Then next time a cell in that column is clicked the table could check in the first row if it is expanded and decide if it should contract back to original or expand. In such a large table users are probably only interested in correlations between a few columns at a time, this method has the advantage that only those columns of interest to them are expanded at any given time.

The third and final option I can think of is to use a humble div. Attach a click element as in the last paragraph, but this time have the event handler create a div over the cell of interest which is large enough to contain all the text and then make it disappear if that div is clicked on.

The most appropriate solution depends on how the users are going to want to use the table data. If you want code snippets for any of the above suggestions, just drop in a comment and/or send me an email.

Good luck! ;)

sillyMunky
-1 for suggesting iframe to do something a div can do perfectly fine, +1 for expandable cells...
peirix
OK so there's a very teeny tiny bit of overhead and extra code to using an iframe. Why even bother with a div? You could just set overflow to scroll in the table's css and get the same effect. I'm sure if he's got this far he's intelligent enough to decide which wrapper is appropriate for his page. I'm used to developing more apps than sites (and maybe that's what he's doing) when it would be preferable in terms of maintainability and flexibility to use iframes. I don't think -1 is appropriate but hey, it's your vote ;) ... what about the 3rd option? is that a 0?
sillyMunky
A: 

This is maybe a different idea: try to use BySlideMenu plugin for Mootools.

It is for menus but maybe it can be in use for your table. Have a look at the example no 4, and next ones.

Ula Karzelek
A: 
MusiGenesis
+1  A: 
amikazmi
@amikazmi: see my answer. This is a lot harder than you might think.
MusiGenesis
This is great, as long as the table headings stay clearly visible - otherwise the user might not know which column(s) to hover over
Waggers
@MusiGenesis: I added a link to a working javascript code in the example, although I didn't try, I don't think it'll be that hard to convert it to a table.@waggers: in the question he said he wanted around 100 columns.. no way you could fit all to the screen AND make them all visible, the beauty of fisheye is that it makes the delta around you hover more visible.. so if you have 100 columns you can make a quick swipe to figure out all the columns
amikazmi
I'd be interested to see a working demo of this
Russ Cam
A: 

jqGrid might be a solution (under Advanced->Resizing). I'm not a big of datagrids but atleast it allows resizing, I haven't tried it with a fixed width table however.

Chris S
+2  A: 

Well, another possible solution: Switch the rows and columns, putting the column headers on the left instead of the top. You would have to scroll horizontally to scroll through the rows (but hey, scrollbars are useful) yet every cell could use the whole width of the screen minus header width.

Thus, switch the X and Y axis of the table. Not pretty, but it could work.

Workshop Alex