Wojtek
Wojtek

Reputation: 455

Grouping nested table rows

What would be the best way of grouping table rows in an HTML table? Some of the groupings are supposed to be nested, so using <tbody> is not an ideal solution (they are not supposed to be nested).

My data has the following format:

Level 1
Level 1
    Level 2
    Level 2
        Level 3
            Level 4
        Level 3
        Level 3
    Level 2
Level 1
    Level 2
        Level 3
            Level 4
            Level 4
        Level 3
    Level 2
        Level 3

What I am trying to achieve:

The table is generated in JavaScript (from a JSON object that has a nested structure), so I can do all sorts of magic to it. The data represents a financial balance sheets, and sometimes you may want do display/hide more detailed information on any particular data row, hence the nesting.

Upvotes: 0

Views: 1839

Answers (3)

krpec
krpec

Reputation: 66

I came to the same problem to solve, here's my solution, I hope it'll help..

The thing for me was to add a few attributes (rowname, parent, state) to each row of the table. State attribute can be either "opened", "collapsed" or "leaf". Then two javascript functions will do the magic, see the working fiddle.

Upvotes: 1

Izekid
Izekid

Reputation: 185

I think there is no good way of doing this in HTML. I would use JQuery Datatable.

http://jquery-datatables-row-grouping.googlecode.com/svn/trunk/customGroupOrdering.html

Try looking at that example

Upvotes: 1

Hima
Hima

Reputation: 12054

You can give try to Vertical menus which will have levels too and collapsible panels too. there are so many templates available . just an idea .

Upvotes: 0

Related Questions