Help:Collapsible tables

From WikiVet English
Jump to navigation Jump to search
Help:ContentsHelp Banner.png
HELP


Collapsible tables provide a way to collapse and uncollapse a table when a show/hide button is clicked.

The initial state of any collapsible content can be controlled using a "collapsible table", because it also allows a table with only one element with content, and a header.

Simple example

Tables are simpler to work with, as you merely need to add the collapsible class to the table itself. For the [hide]/[show] link to appear, the table's first row must be a header row, that is, one of the cells in the first row must be declared with an exclamation mark (in wikisyntax). The use of the class wikitable in the example below is merely for appearance; it is not needed for collapsible to function.

Code entered Output produced
{| class="wikitable collapsible"
! Simple collapsible table
|-
| Lorem ipsum dolor sit amet
|}
Simple collapsible table
Lorem ipsum dolor sit amet

Using the syntax above, collapsible tables are often used to always display an introduction to, or summary of, a lengthy discussion or section of content, while hiding the majority of that content from immediate view. The summary message is put in the header cell, and the content is placed into the body cell. The content is then easily accessible by clicking the 'show' button. The collapsible functionality is also available in larger and more complicated tables, as long as there is a header cell in the first row of the table.

Code entered Output produced
{| class="wikitable collapsible"
 |A normal cell in the header row
 ! colspan="2"| Header cell spans two cols
 |-
 | colspan="2" | Lorem ipsum dolor sit amet
 | Separate body cell
 |}
A normal cell in the header row Header cell spans two cols
Lorem ipsum dolor sit amet Separate body cell

Collapsing tables by default

Just using the collapsible class produces a table which is expanded by default, but can be collapsed by the reader. It is also possible to create tables which are collapsed by default, and can be optionally expanded. There are several methods for doing this, depending on the situations in which you want the table to collapse.

'collapsed'

Adding the collapsed class will cause the table to always be initially collapsed, no matter what happens around it. It is the simplest method for doing so. Using the examples above:

Code entered Output produced
{| class="wikitable collapsible collapsed"
! Simple collapsible table
|-
| Lorem ipsum dolor sit amet
|}
{| class="wikitable collapsible collapsed"
 |A normal cell in the header row
 ! colspan="2"| Header cell spans two cols
 |-
 | colspan="2" | Lorem ipsum dolor sit amet
 | Separate body cell
 |}

'autocollapse'

Adding the autocollapse class causes the table to collapse when there are more than a threshold number of collapsible tables on the page. On en.wiki, this threshold is set at 2. The example below, therefore, collapses because there are numerous collapsible tables on the page.

Code entered Output produced
{| class="wikitable collapsible autocollapse"
! Simple collapsible table
|-
| Lorem ipsum dolor sit amet
|}
Simple collapsible table
Lorem ipsum dolor sit amet

'innercollapse' and 'outercollapse'

Using this pair of classes, it is possible to make a table collapsed by default only when it is contained within a particular object, such as another table. This is mainly useful for tables inside templates, which are often nested.

Code entered Output produced
{| class="wikitable outercollapse"
! This table does not collapse
|-
| But the table inside this cell

{| class="wikitable collapsible innercollapse"
! Does collapse
|-
| Hiding this part
|}

|}
This table does not collapse
But the table inside this cell
Does collapse
Hiding this part

Other notes

Other HTML elements

The code that performs the manipulation only checks for table elements, so these classes will not work for other elements, such as <div> or <span>.