views:

1175

answers:

8

I'm trying to show a tree structure in an HTML table. It's basically a list of people you referred to a site, but you can expand each and see the people they referred too (only 2 or 3 levels). I'm also showing a number of pieces of information on each person, so I'm using a table, with several columns.

I'm wondering what's the best way to display this so that people in lower levels look "indented", but avoiding a mismatch between the data contents and the headers showing what each number means...

I'm mostly looking for stealing ideas here :-) Have you ever seen or done a site that has something like this?


Edit: Thank you for all the answers so far.

I think I failed to correctly explain what I'm trying to do. This is a list of people, but the reason of existence of this report is the numbers attached to each person, not the list itself.
For each person in this "list", I'm going to show data to their right, that needs to be aligned, for example, to have "totals" at the bottom, etc.

Picture, if you will, having Windows Explorer, with the tree on the left, so you can open and close folders, but then, to the right of each folder, you have data like how many files are in there, what kind of information, etc. Just like you get in the right pane in Windows Explorer for "files" (in Details view), only that I do it for the tree on the left. (This is not what i'm doing, but it's the closest analogy I could think of)

This is why I'm leaning towards making a table rather than a List. If these where just the people's names, or a tree of folders, I totally agree than nesting <ul>'s is the way to go. My problem in this case is that the extra data that I need to show for each item is the most important part of the whole report.

A: 

I'd try something using nested divs. I think it would be pretty hard to have it look like one big table with column headings only at the top, so you might be better off considering a new table for each level of nesting, or pivoting it round so you show the data as rows rather than columns.

andygeers
So you're suggesting to have headers again at each "lower level" after each expansion?That *could* work, but I'm trying to avoid it if I can, because it's not going to look very neat.
Daniel Magliola
+3  A: 

...It's basically a list of people...

You don't - this is not tabular data, it's a list (<ul>)

annakata
This is a comment, not an answer
Pablo Fernandez
I disagree. I'm answering that this should not be done, and suggesting an alternative.
annakata
Hmmm, not really, because I'm showing figures next to each person's name. So it IS conceptually a table, regardless of whether I render it as a table (which so far I believe is the easiest way) or not
Daniel Magliola
This is only a comment under the pretense that it's acceptable to stretch the definition of well-defined semantic HTML elements, which isn't the case.
Andrew Noyes
In any case, even if you display a table next to the person's name, that person should be in a list, since this is a list of people. Within your list, you could have tables, in which case you might want to opt for something like a definition list, although those can be tricky to style across browsers. In any case, It think that would be the most semantically appropriate approach.
Andrew Noyes
Guys, don't start a comment/answer flame, please. The main point here is that I need to show columns with data for each person.
Daniel Magliola
@Andrew, I don't agree with that "it should be a list even if you're showing extra data next to each person"...I mean, with that definition, EVERY table should be a list...
Daniel Magliola
Think of it this way, you have a List<People> where People is a complex object - you can implement People as a table if you like, but why would you implement List as a table when a predefined list exists?
annakata
@Daniel: a table is not a list of data, it's a grid, and one with header and footer structure - it's entirely more complex
annakata
@annakata: please read my clarification. This is inherently a table, not a list, even though the underlying data structure is a tree, the information the user wants is a table. It's an old fashioned regular report :-)
Daniel Magliola
@Daniel: Ok, I fundamentally disagree that it is a table, but let me come at this from another angle: afaik it's impossible to do this with CSS with a single table (because of IE incompatabilities) which leaves you with nested tables (strictly worse than the ul situation) or using JS to create/destroy elements. I'm not clear why you're averse to a <ul>. It could be styled to look exactly like a table, without losing semantics.
annakata
@annakata — Why don't you feel that this is a table? While the child/parent relationship of rows complicates things, this sounds very much like tabular data to me — a series of records, each of which contain various values for the same set of columns.
Ben Blank
A: 

Certainly a table is the wrong tool to use I think. Usually, trees are defined as a list of subtrees (plus potentially some data), and thus, I think a semantic transformation into html should use some nested lists (and if you want that dynamicness in there, make sure that you keep all the lists open and CLOSE them with javascript, so they are open if the user has javascript disabled).

In fact, you also said, that you have a LIST of people who accessed the site, so it looks far more like list than a table.

Furthermore, nested lists can be easily formatted using CSS to look pretty nice. At least the effort to make such a nested list look nice is far, far less than trying to get a table to look that nice (I've tried both).

So overall: use a nested list. It fits the datastructure you represent better and it also fits your intuition better and also it can be formatted better in an easier way.

Tetha
+2  A: 

Use the semantically appropriate tag for lists: <ul>. simply nest them. you can hide part of the structure, or maybe create it on the fly.

<ul id='n0>
  <li id='n1'>One guy</li>
  <li id='n2'>Second guy
    <ul id='n2.0'>
      <li id='n2.1'>first one of second guy</li>
      <li id='n2.2'>last of second</li>
    </ul>
  </li>
  <li id='n3'>Third one</li>
</ul>

and so on. the naming of items is up to you, i usually do it either reflect the struture (as here), or the DB ids.

Javier
A: 

So you have lists of people and groups of people. Arrange this as nested lists.

Then you have tabular information about each person. Present this as a series of tables.

Next, link the people to the table. This can be done with <a href="#table_about_person_a"> and <table id="table_about_person_a">

If JavaScript is enabled, load a stylesheet that sets all the tables to display: none;

Attach event handlers to each link in the list that read the href to get the id of the table associated with that user. Set the JS to make the table display: table (or block in IE <= 7).

Due to the issues with Internet Explorer, this is best done by assigning a class to all the tables to hide them, and then removing it to reveal them.

Then add CSS to position the tables beside the list.

Without JS, it should degrade cleanly so that clicking a name will scroll the browser to the table associated with it.

David Dorward
A: 

Daniel, to get a tree structure like the folder hierarchy in windows explorer you will need to have tables, divs, images (to be able to expand collapse), etc . Your divs should hav auto generated or incremental ids. Your div visibility should be set to block or none when the user clicks on the expand/ collapse icon. This should be done in javascript.

I have done a similar thing, where my data was in an xml format containing divisions, projects within the divisions, resources within the projects, etc. I had applied xslt to generate the reqd html output for tree structure. Let me know if your req is the same. So tht I can post you the sample xml, xslt.

Rashmi Pandit
+1  A: 
dalbaeb
Very interesting, this is similar to what i'm doing, to some extent.Is that red thing part of the actual table? does it look like that? Or is that something you added later to mark what changed for me?Because that could be what i'm looking for to emphasize indentation.Thanks!
Daniel Magliola
Padding on the DIV that is wrapped around the table, together with the background-color on the DIV together produce the 'red thing' effect. You can also do it with borders, it's just simple CSS tweaking. Should you come up with a neat technique or example, I would much appreciate it if you shared it here, because we are looking for a clearer way to emphasize indentation, this is not final.
dalbaeb
+1  A: 
John Pirie
That IS the answer :-)Mine was a design question, not an implementation one (I know how to implement it)To do this in a browser, you just use a Table :-)You show and hide rows like dalbaeb suggested, and you use CSS and classes to do the indentation and put backgrounds to show the tree lines.The nested indentations part gets tricky, though... :-( I don't thin you can do that elegantly at all. Either you have different classes defined for the different levels (which sucks and has a limit), or you just generate  's (which just sucks)
Daniel Magliola
Or you could use the <ul> and <li> tags for what they're designed for. You can hide the bullet using the "list-style" family of CSS properties.
Samir Talwar
I agree with Samir, I feel like you're using the table element because of how it looks, which is the wrong approach. Use elements because of what they mean, not how the default styling looks in your web browser; that can always be changed with CSS.
Andrew Noyes
Nice. Too bad we may have different headers on nested tables, otherwise it would be great in my case as well.
dalbaeb
@Samir, Andrew: Without wishing to be argumentative (or sulky :P), it's fairly clear that Daniel had already decided on a table, and because I'm not sure how *this* answer *is* an answer, perhaps the best approach is to offer some actual code which solves this.
annakata
I maintain this isn't the right approach, but I've no desire to see you walk away without an actual answer, so I edited in a basic implementation. Good luck to you.
annakata