views:

274

answers:

4

What is the best way to turn off the visibility of a row(s) and have the gaps removed. Also the reverse, if turning on the visibility making sure that the visible row(s) are displayed again. Thanks

+4  A: 

If you wish to do this on the client (i.e. through javascript) try set the style.display to 'none' (and 'block' to turn it back on).

If you wish to handle it on the server set the visibility of the row to false, this will prevent the row from rendering.

Edit - With example:

function ShowHideRow(row, show)
{
    document.getElementById(row).style.display = (show ? 'block' : 'none');
}

note you may wish to follow the advise of Mufasa and use table-row instead of block.

Chris
Thank you Chris. Appreciate your help.
+1  A: 

You need to set the 'display' property of the row (the ) to 'none'. Through either JavaScript as Chris said or with CSS.

Echilon
Echilon, thanks for your help too. I did try what Chris, and Mufasa stated, also the 'none' and 'block' all is working now.
A: 

Chris is right, except setting the value back to the correct table display type would be a little more correct when showing it again. For a <TR>, you would use display: table-row. See CSS Display Property.

Update: bobince's response is a more practical response on how to use (and not use) the display attribute.

Mufasa
Mufasa, thank you very much for your help.
+4  A: 

If you do it with the display property as suggested so far, you have to worry about block vs. table-row. table-row is correct, but IE doesn't support it, so you have to browser-sniff to choose.

Potentially easier is to avoid setting the style directly, doing it with a CSS class rule instead:

tr.hidden { display: none; }

row.className= 'hidden'; // sets display to none
row.className= ''; // resets display to its default value
bobince
Thanks for all your help. I will try this option also.
Would just like to note that you could try to give your class name a more "semantically meaningful" name such as "disabled" rather than "hidden". You may choose to display the row later anyway and shade it gray rather than hiding it, in which case the class name won't make any sense.
Rahul