Solved

Expandable/ Drill down table

Posted on 2006-07-12
3
571 Views
Last Modified: 2012-06-21
Dear experts,


I would like to create a expandable/ drilldown html table.
For example, a table that displays all the county information of a state within the entire US.
The user should be able to click on an expand button next to the state the view the county information of each state.

The information will be pull from a database using Java.

Any advice are welcome.

Thanks
etalexit

0
Comment
Question by:etalexit
3 Comments
 
LVL 7

Accepted Solution

by:
mmarksbury earned 200 total points
ID: 17095551
There are a few ways...

1. Pull all the information on page load.

2. Pull only the state information on page load and pull the counties on request using AJAX.

I'd go for #2 and get some AJAX experience under your belt (if you dont already have it).

So for example....with each state you might have...

<td>
     <a href="javascript:GetCounties('CA');">California</a><br />
     <div id="CA_Counties"></div>
</td>

Then you would write a Javascript function that uses AJAX to call the server and get all Counties for the state "CA".  Parse the response XML and populate the CS_Counties DIV with the values.
0
 

Assisted Solution

by:Colcob
Colcob earned 200 total points
ID: 17097002
I dont have any AJAX experience, so I can only tell you how to do it via mmarksbury's method 1.

I've done a technical library browser with pop-out subsections like this.

First, you have a javascript function called toggle, which simply changes the display style from block to none, or none to block.  Thus you can call that function on any block level element and it will show or hide it, regardless of its current state (i havent got the code to hand, but if its something you couldnt do yourself, I can dig it out).

You'll need to pull the full dataset of states and counties into the page, presumably as a two-level array, then its a case of creating your tables with hidden sections for the counties which are revealed when you click on the states.

Unfortunately, I dont think you can show/hide individual rows in a table, as they aren't block level elements, so I had to create the thing out of lots of separate tables and bunch them together with the styling. EG:

<table class="state"><tr><td><a onClick="javascript: toggle(stateCounties1)">State1</td></tr></table>
     <table class="county" id="stateCounties1">
       <tr><td>State1county1</td></tr>
       <tr><td>State1county2</td></tr>
       <tr><td>State1county3</td></tr>
    </table>

<table class="state"><tr><td><a onClick="javascript: toggle(stateCounties2)">State2</td></tr></table>
     <table class="county" id="stateCounties2">
       <tr><td>State2county1</td></tr>
       <tr><td>State2county2</td></tr>
       <tr><td>State2county3</td></tr>
    </table>

Etc:
So you use CSS to set table.county to display: none; so the counties dont show up to start with, all the id's and arguments in the toggle function need to be set by the values from the db so they tie up with eachother, and you should be good to go.

Note, I did this a while ago, and I suspect there is a more modern sematic way of doing it with Lists instead of Tables, but I havent tried it myself.  A UL is a block level element, so I'm sure you can probably use UL's instead of tables.


0
 
LVL 44

Assisted Solution

by:scrathcyboy
scrathcyboy earned 100 total points
ID: 17103463
Just about everyone is doing this in javascript, like the two responses above.  Even microsoft does this on their "knowledgebase" webpages.  The issue you have to deal with is -- if you do it all in javascript, within the page, that page will become HUGE, and take a long time to load.

Therefore, I option 2 of mmarksburys above is definitiely the best.  Use a DIV for each county data, and keep the county data in separate files, and read those files into the DIV if and only if a person clicks on the link to the counties of that state.  A little more code, but a much faster site response.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question