version=pmwiki-2.2.61 ordered=1 urlencoded=1
author=Petko
charset=UTF-8
csum=
name=PmWiki.TableDirectives
rev=81
targets=PmWiki.Tables,PmWiki.TableDirectives,PmWiki.Audiences,PmWiki.PmWikiPhilosophy,PmWiki.LocalCustomizations,PmWiki.IncludeOtherPages,Cookbook.AdvancedTableDirectives,Cookbook.BackgroundImages,PmWiki.WikiStyles,PmWiki.TableDirectives-Talk,Cookbook.CreateColumns
text=(:Summary:Directives for table processing:)(:Audience: authors (intermediate) :)(:title Table directives:)%0aThere are six directives for table processing. All must be at the beginning of a line to have any effect.%0a%0a!!!@@[=(:table [attr...]:)=]@@%0a%0aGenerates a new HTML %3ctable> tag with the attributes provided in ''attr...''.%0aCloses the previous table, if any.%0aValid attributes and values are:%0a* border ''(a positive integer)''%0a* bordercolor ''(a color name or hex number; doesn't display in all browsers)''%0a* cellspacing ''(a positive integer indicating the space between cells)''%0a* cellpadding ''(a positive integer indicating the interior border of a cell)''%0a* width ''(a positive integer or percent)''%0a* bgcolor ''(a color name or hex number)''%0a* align ''(left, center or right)''%0a* summary ''(does not display; used primarily to help visually disabled people navigate)''%0a%0a!!!@@[=(:cellnr [attr...]:), (:cell [attr...]:), (:headnr [attr...]:), (:head [attr...]:) =]@@%0a%0a* The @@ [=(:head:)=] @@ directive opens a new "header cell" of the table (creates @@ %3cth> @@ tag in HTML).%0a* The @@ [=(:cell:)=] @@  directive opens a new "regular cell" of the table (creates @@ %3ctd> @@ tag in HTML).%0a* The directives @@ [=(:headnr:)=] @@ and @@ [=(:cellnr:)=] @@ open a new cell on a new row in the table.%0a%0aThese directives close any previous cell and/or row. Note, the @@ [=(:head:)=] @@ and @@ [=(:headnr:)=] @@ directives exist from PmWiki version 2.2.11 or newer.%0a%0aValid attributes and values are:%0a* align ''(left, center or right)''%0a* valign ''(top, middle or bottom)'' * ''default is "top", see note below''%0a* colspan ''(a positive integer)''%0a* rowspan ''(a positive integer)''%0a* bgcolor ''(a color name or hex number)''%0a* width ''(a positive integer or percent)''%0a* class ''(a CSS class of the cell)''%0a* style ''(custom CSS styles of the cell)''%0a%0a!!! @@ [=(:tableend:)=] @@%0a%0aCloses the previous table cell and closes off any table. Generates %3c/th>, %3c/td>, %3c/tr>, and %3c/table> tags as needed.%0a%0a!!!* valign attribute%0a%0aIf not already set, PMWiki will automatically include the attribute valign='top' with all [@(:cell[nr]:)@] and [@(:head[nr]:)@].  Pm said "Table Directives were created for layout purposes and in that case it makes the most sense for each cell (column) to have its content at the top of the row.  The attribute is placed in each cell and not in the row because certain browsers didn't recognize valign='top' in the row tag.%0a%0aSee $EnableTableAutoValignTop on how to disable the automatic insertion of the attribute.%0a%0a!! Notes%0a%0aFor the table, cell, and cellnr tags the author can specify any attributes that would be valid in the HTML %3ctable> or %3ctd> tags.  Thus you can specify rowspan, colspan, etc. arguments to build arbitrary tables.  However, it's not possible to nest a [@(:table:)@] inside of a [@(:cell:)@] or [@(:cellnr:)@] -- the next paragraph explains why.%0a%0aMany are likely to ask why we didn't just use the standard HTML table markup (%3ctable>, %3ctr>, %3ctd>, %3cth>) instead of creating a new markup, and allowing nested tables as a result.  There are two answers:  first, the HTML table markup is very ugly for naive authors (see [[PmWiki.Audiences]] and [[PmWikiPhilosophy]] #2), and second, it'd be very easy for authors to create tables that are incorrect HTML and that display incorrectly (or not at all) on some browsers.  Even seasoned web professionals sometimes get the table markup wrong, so it's a bit unrealistic to expect the average author to always get it right, or to be able to read arbitrary HTML table markup that someone else has created.%0a%0a-> %25color=green%25 ''Common comment:'' Surely, the average or naive author would not be writing HTML directly, but using a tool, such as [=FrontPage=], or even [=MSWord=], to generate the HTML. This would be a lot simpler than learning even the simplest PmWiki markups.%0a>>%3c%3c%0a%0a-> %25color=green%25 ''Pm's Response:'' And once the HTML has been generated and posted, how is someone else going to edit or modify the table if they don't have the original [=FrontPage or MSWord=] file used to create it?  Remember that we're talking about ''collaborative'' authoring.  The HTML that those packages generate is among the hardest to read and edit of all!%0a%0aIt's difficult to write the code needed to make PmWiki understand and fix arbitrary table markup, so PmWiki uses the simplified version above.  Still, this version is able to handle most table requirements (with the possible exception of nested tables).%0a%0aAnd, this is not to say that nested HTML tables are impossible in PmWiki --they just can't be easily created by wiki authors using the default wiki markup.  A site administrator can of course create header/footer HTML code and other [[local customizations]] that make use of nested tables.%0a%0a!!!Example 1.  A table using table directive markup.%0a%0a"[@&nbsp;@]" is a non-breaking space in html. Place it in a cell if a cell is to be empty or the border of the cell will not be drawn properly.%0a%0a(:markup:)%0a(:table border=1 cellpadding=5 cellspacing=0:)%0a(:head:) a1%0a(:cell:) b1%0a(:cell:) c1%0a(:cell:) d1%0a(:headnr:) a2%0a(:cell:) b2%0a(:cell:) c2%0a(:cell:) &nbsp;%0a(:tableend:)%0a(:markupend:)%0a%0a%0aIn HTML, this is the same as%0a%0a-> [@%0a%3ctable border='1' cellpadding='5' cellspacing='0'>%0a  %3ctr>%0a    %3cth>a1%3c/th>%0a    %3ctd>b1%3c/td>%0a    %3ctd>c1%3c/td>%0a    %3ctd>d1%3c/td>%0a  %3c/tr>%0a  %3ctr>%0a    %3cth>a2%3c/th>%0a    %3ctd>b2%3c/td>%0a    %3ctd>c2%3c/td>%0a    %3ctd>&nbsp;%3c/td>%0a  %3c/tr>%0a%3c/table>%0a@]%0a%0a%0a-----%0a!!!Floating Table with bulleted navigation list%0a%0aWhat if you wanted to create a nice little table like a table of contents in a page like this? In this example, the table is floating right and contains some links in a bulleted list. This is a nice demonstration of how it's possible to build a little table of contents in the page, which might navigate to other pages just within the same wiki group. Note that having a bulleted list ''won't work in a ordinary table'' - it only works inside an  table created with table directives such as the example code used here.%0a%0a(:markup:)%0a(:table border=1 width=30%25 align=right bgcolor=#cccc99 cellspacing=0 :)%0a(:cellnr:)%0a'''Navigation Links'''%0a(:cellnr:)%0a*[[Tables]]%0a*[[Table directives]]%0a(:tableend:)%0a(:markupend:)%0a%0a(:markup:)%0a(:table border=1 width=30%25 align=right bgcolor=#cccc99 cellspacing=0 :)%0a(:cellnr colspan=2 align=center:)%0a'''Navigation Links'''%0a(:cellnr align=center:)%0a[[Tables]]%0a(:cell align=center:)%0a[[Table directives]]%0a(:tableend:)%0a(:markupend:)%0a%0aLooking at the markup here, notice that we have used a #cccc99 hex color for the table background. Also, the [@(:cellnr:)@] markup creates a new row, a new cell and closes the row at the end.%0a%0aYou could take this concept a little further: since you might want each page in the group to contain the same table of contents, you can make ONE table like the above and put it in its own page.  Then use an [[include (other pages)]] on any of your pages and bring in the table. The float (align) property will be honored in each page where it's included.%0a%0a>>faq%3c%3c [[#faq]]%0a%0aQ: Can I define table headers using the table directive markup?%0aA: Yes, use [@(:head:)@] or [@(:headnr:)@] with PmWiki version 2.2.11 or newer. See also Cookbook:AdvancedTableDirectives.%0a%0aQ: Is it possible to do nested tables?%0aA: Yes, if you nest [[Tables|simple tables]] inside advanced tables. See also Cookbook:AdvancedTableDirectives.%0a%0aQ: Is it possible to add background images to tables and table cells?%0aA: Yes, see Cookbook:BackgroundImages.%0a%0aQ: Is it possible to apply styles to the elements of the table, like an ID to the table row, or a class/style to the TD?%0aA: Yes, see [[PmWiki.WikiStyles#WikiStyleApply | $WikiStyleApply]].%0a%0aQ: Is it possible to automatically generate columns or rows in tables, i.e. without having to do a lot of counting?%0aA: Yes, this is possible with the Cookbook:CreateColumns recipe - it allows you to specify a certain number of columns, and/or to specify a certain number of items per column. Plus, someone has provided some similar markup on the [[(PmWiki:)TableDirectives-Talk]] page.
time=1393589792
title=Table directives
