0

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.

4 Answers 4

4

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.

0
4

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
1
  • 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
    Mar 21, 2009 at 21:09
1

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

1
  • Echilon, thanks for your help too. I did try what Chris, and Mufasa stated, also the 'none' and 'block' all is working now. Mar 20, 2009 at 15:02
0

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.