Depending on your needs, David's thought does work well. I do a lot of reporting with HTML in the web viewer and the folding works great.
Andy LeCates demonstrated this using subsummaries at DevCon either last year or the year before (can't remember now). The subsummaries are based on the record IDs and then you can make them appear / disappear based on either a variable, a global field, or the currently selected record (depending on what you want to make happen).
Another possibility is to use a self-joining filtered portal and a return-delimited list of record IDs; this was demonstrated in 2011 by Ernest Koe. That one's a little complicated, because it uses a recursive List function (i.e., List ( List ( ))) and the Virtual List technique, but it does work. (Basically, you set the join to match on the record IDs in the list and then set and reset the list based on when the user clicks the buttons / headers.)
These can be pretty complicated techniques, but if you want to do it FileMaker-native instead of in the Web Viewer, it's possible. (Not that I've done it, mind you; I've just seen other people do it.)
Ernest also demonstrated a SQL query that can do the same thing with just a couple lines. I don't know how he did it, though, since his demo file doesn't seem to be available.