www.webdeveloper.com
Results 1 to 11 of 11

Thread: show/hide table row

  1. #1
    Join Date
    Sep 2007
    Posts
    27

    show/hide table row

    Is it possible to show/hide rows in a table?

    I'm able to do hide tables by wrapping them in divs, but i need to hide JUST the columns. Let me know if this is possible, or if there is a way to emulate it.

  2. #2
    Join Date
    Dec 2005
    Location
    TX
    Posts
    7,943
    Try a search of this forum for items like this: show hide table columns for some other ideas http://www.webdeveloper.com/forum/sh...+table+columns

  3. #3
    Join Date
    Sep 2007
    Posts
    27
    My question was how to hide a row, akak hide/show this whole section:

    <tr>
    <td>
    Content
    </td>
    <td>
    Content
    </td>
    </tr>

    That link only explains how to hide a span of content, something I can already do.

  4. #4
    Join Date
    Nov 2006
    Posts
    530
    Dang. I thought you had asked to hide columns (which is more difficult) so I wrote code to do that. Oh well, I added additional code to hide a row and left the column code in as well:

    Code:
    <html>
    <head>
    
    <script type="text/javascript">
    
      function hideCol(column, hideVal) {
    
        var row = 0;
        var displayStyle;
    
        while (document.getElementById('r'+row+'c'+column)) {
          var displayStyle = (hideVal!=true)? 'inline' : 'none' ;
          document.getElementById('r'+row+'c'+column).style.display = displayStyle;
          row++;
        }
    
      }
    
      function hideRow(row, hideVal) {
        if (document.getElementById('row'+row)) {
          var displayStyle = (hideVal!=true)? 'inline' : 'none' ;
          document.getElementById('row'+row).style.display = displayStyle;
        }
      }
    
    </script>
    
    </head>
    <body>
    
      <table border="1" cellpadding="10">
        <tr>
          <th>&nbsp;</th>
          <th id="r0c1">Column 1</th>
          <th id="r0c2">Column 2</th>
          <th id="r0c3">Column 3</th>
          <th id="r0c4">Column 4</th>
        </tr>
        <tr id="row1">
          <td><b>Row 1</b></td>
          <td id="r1c1">Row-1 Col-1</td>
          <td id="r1c2">Row-1 Col-2</td>
          <td id="r1c3">Row-1 Col-3</td>
          <td id="r1c4">Row-1 Col-4</td>
        </tr>
        <tr id="row2">
          <td><b>Row 2</b></td>
          <td id="r2c1">Row-2 Col-1</td>
          <td id="r2c2">Row-2 Col-2</td>
          <td id="r2c3">Row-2 Col-3</td>
          <td id="r2c4">Row-2 Col-4</td>
        </tr>
        <tr id="row3">
          <td><b>Row 3</b></td>
          <td id="r3c1">Row-3 Col-1</td>
          <td id="r3c2">Row-3 Col-2</td>
          <td id="r3c3">Row-3 Col-3</td>
          <td id="r3c4">Row-3 Col-4</td>
        </tr>
        <tr id="row4">
          <td><b>Row 4</b></td>
          <td id="r4c1">Row-4 Col-1</td>
          <td id="r4c2">Row-4 Col-2</td>
          <td id="r4c3">Row-4 Col-3</td>
          <td id="r4c4">Row-4 Col-4</td>
        </tr>
    
      </table>
    <br>
    <a href="#" onclick="hideRow(1, true);">Hide Row 1</a>
    &nbsp;&nbsp;&nbsp;
    <a href="#" onclick="hideRow(1, false);">Show Row 1</a>
    <br>
    <a href="#" onclick="hideRow(2, true);">Hide Row 2</a>
    &nbsp;&nbsp;&nbsp;
    <a href="#" onclick="hideRow(2, false);">Show Row 2</a>
    <br>
    <a href="#" onclick="hideRow(3, true);">Hide Row 3</a>
    &nbsp;&nbsp;&nbsp;
    <a href="#" onclick="hideRow(3, false);">Show Row 3</a>
    <br>
    <a href="#" onclick="hideRow(4, true);">Hide Row 4</a>
    &nbsp;&nbsp;&nbsp;
    <a href="#" onclick="hideRow(4, false);">Show Row 4</a>
    <br><br>
    
    <a href="#" onclick="hideCol(1, true);">Hide Column 1</a>
    &nbsp;&nbsp;&nbsp;
    <a href="#" onclick="hideCol(1, false);">Show Column 1</a>
    <br>
    <a href="#" onclick="hideCol(2, true);">Hide Column 2</a>
    &nbsp;&nbsp;&nbsp;
    <a href="#" onclick="hideCol(2, false);">Show Column 2</a>
    <br>
    <a href="#" onclick="hideCol(3, true);">Hide Column 3</a>
    &nbsp;&nbsp;&nbsp;
    <a href="#" onclick="hideCol(3, false);">Show Column 3</a>
    <br>
    <a href="#" onclick="hideCol(4, true);">Hide Column 4</a>
    &nbsp;&nbsp;&nbsp;
    <a href="#" onclick="hideCol(4, false);">Show Column 4</a>
    <br>
    
    </body>
    </html>

  5. #5
    Join Date
    Sep 2007
    Posts
    27
    Thank you!

  6. #6
    Join Date
    Aug 2005
    Location
    Singapore
    Posts
    155
    [URL=http://www.samliew.com]Personal Website[/COLOR] | Programming Page

  7. #7
    Join Date
    Dec 2005
    Location
    TX
    Posts
    7,943

    Question Confused:

    Concerning post #2 and the response of #3, this was the ORIGINAL requirement.
    but i need to hide JUST the columns
    Hope you are getting what you want.

  8. #8
    Join Date
    Aug 2005
    Location
    Singapore
    Posts
    155
    Yup, but I expanded on that in case next time somebody wants to hide rows instead, or something else.
    [URL=http://www.samliew.com]Personal Website[/COLOR] | Programming Page

  9. #9
    Join Date
    Mar 2008
    Posts
    1
    Thank you Mjdamato - you Rock! - I really needed your help and your code is easy to understand as well as edit - thank you again.

  10. #10
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Code:
    var displayStyle = (hideVal!=true)? 'inline' : 'none' ;
    That will work in IE only. Mozilla (and all the DOM full compliant browsers) will not accept "inline" as positive display for table's elements. You should use a empty value for a positive display, as a crossbrowser solution:
    Code:
    var displayStyle = (hideVal!=true)? '' : 'none' ;

  11. #11
    Join Date
    May 2006
    Location
    Odenton, MD
    Posts
    1,449
    just a thought, nobody feel is useless the function hideCol?
    function hideCol(column, hideVal) {

    var row = 0;
    var displayStyle;

    while (document.getElementById('r'+row+'c'+column)) {
    var displayStyle = (hideVal!=true)? 'inline' : 'none' ;
    document.getElementById('r'+row+'c'+column).style.display = displayStyle;
    row++;
    }

    }
    instead of traveling each row to hide the proper cell, why not use the collapse property for column? so, the proper html is:
    HTML Code:
    <table id='mytable'>
    <col /><col /><col />...
    ...
    </table>
    where <col /> represent an single column and there should be as many <col /> as necessary (that is, a <col /> for each table's column). then, hideCol is redefined to apply col.style.visibility = 'collapse'; to the desired column.
    my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous.
    my nature language is javascript, then come spanish and english -- me

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.22590 seconds
  • Memory Usage 2,954KB
  • Queries Executed 13 (?)
More Information
Template Usage (35):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (3)bbcode_code
  • (1)bbcode_html
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (11)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (11)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates