HTML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignHTML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 13th, 2013, 06:27 PM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 294 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 8 h 6 m 9 sec
Reputation Power: 5
Get TBODY of table to scroll

Originally, I made a seperate line of headers, then below that made a table within <DIV>'s, and had that scroll. My issue now is make the headers sort column onClick. To do this, I can't have them 2 seperate items. Sorting works fine, but the TBODY portion I wish to only be like 500px tall, and not the whole page. How would I do this?

Kinda an idea of my goal:

Code:
<TABLE>
  <THEAD>
    <TR>
      <TD>...</TD>  <-- Multiple headers to SIT STILL and allowing clicking to sort
    </TR>
  </THEAD>
  <TBODY>
    <TR>
      <TD>...</TD>  <-- A thousand or so rows to list, and keep in a scrollable 500px tall area
    </TR>
  </TBODY>
</TABLE>


As far as my sorting, it is in place and successful, but not designed for a scrolling area.

http://www.kryogenix.org/code/browser/sorttable/

EDIT: I did try placing the TBODY in its own DIV and get that to display as desired, but no luck. I currently have the whole table within my DIV which does stand the 500px tall and is scrollable. Just gotta get the HEADERS somehow locked.

Last edited by Triple_Nothing : February 13th, 2013 at 06:31 PM.

Reply With Quote
  #2  
Old February 13th, 2013, 06:55 PM
null.if.ied null.if.ied is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 26 null.if.ied User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 15 m
Reputation Power: 0
I've found an implementation of what you're looking for at: http://www.cssplay.co.uk/menu/tablescroll.html

The author has graciously allowed the reuse of his code, with attribution, and you can learn more about it from his website ... but I'll delve into the reasons why his solution works here.

The table is wrapped in two divs, .outer and .innera. Those divs have the following properties:

.outer:
css Code:
Original - css Code
  1. .outer {
  2. position:relative;
  3. padding:4em 0 3em 0;
  4. width:54em;
  5. background:#eee;
  6. margin:0 auto 3em auto;
  7. }


.innera:
css Code:
Original - css Code
  1. .innera {
  2. overflow:auto;
  3. width:54em;
  4. height:9.6em;
  5. background:#eee;
  6. }


Now this is the important bit which enables his solution; each TR within a THEAD has the following styles applied to it:

css Code:
Original - css Code
  1. .outer thead tr {
  2. position:absolute;
  3. top:1.5em;
  4. height:1.5em;
  5. left:0;
  6. }


What this is doing is the following: specify a height for the div containing the table via the .inner class (height:9.6em;), and force the contents of that div to be scrollable (overflow: auto;).

Now, were you to just implement the overflow: auto; on a div with a specified height wrapped around your table, the entire table - headers and all - would scroll. This is where relative/absolute positioning come into play...

Since the .outer class uses relative positioning (position: relative;), any element within it can be absolutely positioned (position: absolute;). An absolutely positioned element stays put. It does not scroll: it sticks to whatever geometry you assign it.

So, when the author specifies (top:1.5em; left:0;) it means this: "Force all of the TR's within THEAD tags under the .outer class to absolutely position themselves 0px from the left edge of the containing div, and 1.5em from the top."

Ergo the entire table still scrolls as discussed before, the only difference now is that you've told the THEAD's to stay put at a certain location regardless of scrolling, thereby achieving the result you're aiming for.

- Null

Reply With Quote
  #3  
Old February 13th, 2013, 07:44 PM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 294 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 8 h 6 m 9 sec
Reputation Power: 5
Excellent! After minimal tampering with, all works excellent EXCEPT.....

The first row now seems to be rather independant, and so does its sizing in column width. Will I need to manually define widths for each column, or is there a way for it to hold matching widths as the rest?


EDIT: Actually, first row is fine now. After the defining the THEAD and TBODY, I forgot to add in the class attribute. Now the cells in THEAD hold correct widths, but not the rest. My table-layout is 'fixed', so the rest of the columns are equally spaced. Anyone know how to adjust columns as desired?

Last edited by Triple_Nothing : February 13th, 2013 at 08:08 PM.

Reply With Quote
  #4  
Old February 13th, 2013, 08:08 PM
null.if.ied null.if.ied is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 26 null.if.ied User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 15 m
Reputation Power: 0
Quote:
Originally Posted by Triple_Nothing
Will I need to manually define widths for each column, or is there a way for it to hold matching widths as the rest?


I'm not sure what your code looks like since you've implemented the changes, but to steal from the linked example's source once again:

html Code:
Original - html Code
    <thead>   <tr>     <th scope="col">FLIGHT CODE</th>     <th scope="col">FROM</th>     <th scope="col">STA</th>     <th scope="col">ETA</th>     <th scope="col" class="nd">Notes</th>   </tr> </thead>


Note that the author is using <TH> tags with scope="col" specified instead of <TD> tags.

You can read more about TH tags and the scope attribute here: https://developer.mozilla.org/en-US...TML_Elements/th

- Null

Reply With Quote
  #5  
Old February 13th, 2013, 08:32 PM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 294 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 8 h 6 m 9 sec
Reputation Power: 5
I've tried many things. It seems the thing getting me stuck is the table-layout: fixed;

If I remove it, table expands as wide as needed to fit all content in its cell, which is not desired. If I replace it, and don't detatch the header as we've done, every column has the desired width. Once we pull the THEAD and TBODY apart, the THEAD has desired widths, but the TBODY has even widths. i.e. Table width is 1000px w/ 5 columns, so every col is 200px.

Reply With Quote
  #6  
Old February 13th, 2013, 09:13 PM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 294 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 8 h 6 m 9 sec
Reputation Power: 5
I removed class/id atts from the td/th tags to define widths, and inserted <colgroup><col> items to define width. They were placed after the TABLE tag, and adjust width desireably on TBODY columns, but not THEAD. :-/ Any ideas with this one?

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignHTML Programming > Get TBODY of table to scroll

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap