none
[openafs-wiki.git] / TWiki / TablePlugin.mdwn
1 # <a name="Table Plugin"></a> Table Plugin
2
3 Gives extra control of table display:
4
5 - Allows sorting
6 - Changing table properties like border width, cell spacing and cell padding
7 - Changing background color and text color for header cells
8 - Changing background color and text color for data cells - colors can _alternate_
9 - Table attributes can be set and overridden in this order:
10   - Default `TABLEATTRIBUTES` Plugin setting in this topic.
11   - A `TABLEATTRIBUTES` preferences setting on site-level ([[TWikiPreferences]]) or web-level (any [[WebPreferences]]), e.g.
12     - `Set TABLEATTRIBUTES = tableborder="0" cellpadding="1" ...`
13   - Before a table using `%TABLE{...}%`
14
15 ## <a name="Sorting"></a> Sorting
16
17 Click on column heading text to sort by a column. Initial column will be sorted in descending order, click again to get ascending order. The type of data in the cell is determined automatically:
18
19 - date if format is:
20   - dd MMM YYY - hh:mm
21   - dd-MMM-YY or dd-MM-YYYY (can be / or space in place of -)
22   - MMM is Jan, Feb, etc
23 - number is digits, with optional decimal point
24 - otherwise treated as text
25
26 ## <a name="%TOPIC% Global Settings"></a> %TOPIC% Global Settings
27
28 Plugin settings are stored as preferences variables. To reference a plugin setting write <code>**%&lt;plugin&gt;\_&lt;setting&gt;%**</code>, for example, <code>**%INTERWIKIPLUGIN\_SHORTDESCRIPTION%**</code>
29
30 - One line description, shown in the [[TextFormattingRules]] topic:
31   - Set SHORTDESCRIPTION = Control attributes of tables and sorting of table columns
32
33 - Set DEBUG to 1 to get debug messages in `data/debug.txt`. Default: `0`
34   - Set DEBUG = 0
35
36 - Make sortable:
37   - #Set SORT = attachments
38   - Set SORT = all
39   - #Set SORT = none
40
41 - Default table attributes:
42   - Set TABLEATTRIBUTES = tableborder="1" cellpadding="0" cellspacing="1" headerbg="#99CCCC" databg="#FFFFCC, #FFFFFF"
43
44 ## <a name="Table Attributes"></a> Table Attributes
45
46 Attributes are defined as a `TABLEATTRIBUTES` Plugin setting in this topic, a `TABLEATTRIBUTES` preferences setting, or on line before the table using `%TABLE{...}%`:
47
48 <table border="1" cellpadding="0" cellspacing="0" style="border-width: 1px">
49   <tr>
50     <th bgcolor="#6b7f93" maxcols="0" style=""><a href="http://localhost?sortcol=0;table=1;up=0#sorted_table" rel="nofollow" title="Sort by this column"><font color="#ffffff">Argument</font></a></th>
51     <th bgcolor="#6b7f93" maxcols="0" style=""><a href="http://localhost?sortcol=1;table=1;up=0#sorted_table" rel="nofollow" title="Sort by this column"><font color="#ffffff">Comment</font></a></th>
52     <th bgcolor="#6b7f93" maxcols="0" style=""><a href="http://localhost?sortcol=2;table=1;up=0#sorted_table" rel="nofollow" title="Sort by this column"><font color="#ffffff">Example</font></a></th>
53   </tr>
54   <tr>
55     <td bgcolor="#ecf2f8" style=""><code>sort</code></td>
56     <td bgcolor="#ecf2f8" style=""> Set table sorting <code>on</code> or <code>off</code></td>
57     <td bgcolor="#ecf2f8" style=""><code>sort="on"</code></td>
58   </tr>
59   <tr>
60     <td bgcolor="#ffffff" style=""><code>initsort</code></td>
61     <td bgcolor="#ffffff" style=""> Column to sort initially (1 to number of columns) </td>
62     <td bgcolor="#ffffff" style=""><code>initsort="2"</code></td>
63   </tr>
64   <tr>
65     <td bgcolor="#ecf2f8" style=""><code>initdirection</code></td>
66     <td bgcolor="#ecf2f8" style=""> Initial sorting direction for <code>initsort</code>, set to <code>up</code> or <code>down</code></td>
67     <td bgcolor="#ecf2f8" style=""><code>initsort="down"</code></td>
68   </tr>
69   <tr>
70     <td bgcolor="#ffffff" style=""><code>headerbg</code></td>
71     <td bgcolor="#ffffff" style=""> Header cell background colour. Choose one of the [[TWiki/StandardColors]]</td>
72     <td bgcolor="#ffffff" style=""><code>headerbg="#99CCCC"</code></td>
73   </tr>
74   <tr>
75     <td bgcolor="#ecf2f8" style=""><code>headercolor</code></td>
76     <td bgcolor="#ecf2f8" style=""> Header cell text colour </td>
77     <td bgcolor="#ecf2f8" style=""><code>headercolor="#0000CC"</code></td>
78   </tr>
79   <tr>
80     <td bgcolor="#ffffff" style=""><code>databg</code></td>
81     <td bgcolor="#ffffff" style=""> Data cell background colour, a comma separated list. Specify <code>"none"</code> for no colour, that is to use the colour/background of the page the table is on. </td>
82     <td bgcolor="#ffffff" style=""><code>databg="#C8CB8F, #DBDDB5"</code></td>
83   </tr>
84   <tr>
85     <td bgcolor="#ecf2f8" style=""><code>datacolor</code></td>
86     <td bgcolor="#ecf2f8" style=""> Data cell text colour, a comma separated list </td>
87     <td bgcolor="#ecf2f8" style=""><code>datacolor="#0000CC, #000000"</code></td>
88   </tr>
89   <tr>
90     <td bgcolor="#ffffff" style=""><code>tableborder</code></td>
91     <td bgcolor="#ffffff" style=""> Table border width (pixels) </td>
92     <td bgcolor="#ffffff" style=""><code>tableborder="2"</code></td>
93   </tr>
94   <tr>
95     <td bgcolor="#ecf2f8" style=""><code>cellpadding</code></td>
96     <td bgcolor="#ecf2f8" style=""> Cell padding (pixels) </td>
97     <td bgcolor="#ecf2f8" style=""><code>cellpadding="0"</code></td>
98   </tr>
99   <tr>
100     <td bgcolor="#ffffff" style=""><code>cellspacing</code></td>
101     <td bgcolor="#ffffff" style=""> Cell spacing (pixels) </td>
102     <td bgcolor="#ffffff" style=""><code>cellspacing="3"</code></td>
103   </tr>
104   <tr>
105     <td bgcolor="#ecf2f8" style=""><code>valign</code></td>
106     <td bgcolor="#ecf2f8" style=""> Vertical alignment of cells, set to <code>top</code>, <code>middle</code>, <code>bottom</code> or <code>baseline</code></td>
107     <td bgcolor="#ecf2f8" style=""><code>valign="top"</code></td>
108   </tr>
109   <tr>
110     <td bgcolor="#ffffff" style=""><code>headeralign</code></td>
111     <td bgcolor="#ffffff" style=""> Header cell alignment, set to <code>left</code>, <code>center</code>, <code>right</code> or <code>justify</code>. Overrides individual cell settings </td>
112     <td bgcolor="#ffffff" style=""><code>headeralign="left"</code></td>
113   </tr>
114   <tr>
115     <td bgcolor="#ecf2f8" style=""><code>dataalign</code></td>
116     <td bgcolor="#ecf2f8" style=""> Data cell alignment, set to <code>left</code>, <code>center</code>, <code>right</code> or <code>justify</code>. Overrides individual cell settings </td>
117     <td bgcolor="#ecf2f8" style=""><code>dataalign="center"</code></td>
118   </tr>
119   <tr>
120     <td bgcolor="#ffffff" style=""><code>tablewidth</code></td>
121     <td bgcolor="#ffffff" style=""> Table width: Percentage of window width, or absolute pixel value. Default is unspecified </td>
122     <td bgcolor="#ffffff" style=""><code>tablewidth="100%"</code></td>
123   </tr>
124   <tr>
125     <td bgcolor="#ecf2f8" style=""><code>columnwidths</code></td>
126     <td bgcolor="#ecf2f8" style=""> Column widths: Comma delimited list of column widths, percentage or absolute pixel value. Default is unspecified </td>
127     <td bgcolor="#ecf2f8" style=""><code>columnwidths="80%, 20%"</code></td>
128   </tr>
129   <tr>
130     <td bgcolor="#ffffff" style=""><code>headerrows</code></td>
131     <td bgcolor="#ffffff" style=""> Number of header rows to exclude from sort; default 1 </td>
132     <td bgcolor="#ffffff" style=""><code>headerrows="1"</code></td>
133   </tr>
134   <tr>
135     <td bgcolor="#ecf2f8" style=""><code>footerrows</code></td>
136     <td bgcolor="#ecf2f8" style=""> Number of footer rows to exclude from sort; default 0 </td>
137     <td bgcolor="#ecf2f8" style=""><code>footerrows="1"</code></td>
138   </tr>
139 </table>
140
141 The `%TABLE{...}%` settings override `TABLEATTRIBUTES` preferences settings, which override the `TABLEATTRIBUTES` Plugin settings.
142
143 ## <a name="Example"></a> Example
144
145 Line before table: `%TABLE{ sort="on" tableborder="0" cellpadding="1" cellspacing="3" headerbg="#000099" headercolor="#FFFFCC" databg="#C8CB8F, #DBDDB5" headerrows="2" footerrows="1" }%`
146
147 <table border="0" cellpadding="1" cellspacing="3" style="border-width: 0px">
148   <tr>
149     <th bgcolor="#000099" colspan="6" maxcols="0" style=""><span><font color="#FFFFCC"> <strong> Table with two Header Rows and Footer Row </strong> </font></span></th>
150   </tr>
151   <tr>
152     <th bgcolor="#000099" maxcols="0" style=""><a href="http://localhost?sortcol=0;table=2;up=0#sorted_table" rel="nofollow" title="Sort by this column"><font color="#FFFFCC">Num</font></a></th>
153     <th bgcolor="#000099" maxcols="0" style=""><a href="http://localhost?sortcol=1;table=2;up=0#sorted_table" rel="nofollow" title="Sort by this column"><font color="#FFFFCC">Status</font></a></th>
154     <th bgcolor="#000099" maxcols="0" style=""><a href="http://localhost?sortcol=2;table=2;up=0#sorted_table" rel="nofollow" title="Sort by this column"><font color="#FFFFCC">Action</font></a></th>
155     <th bgcolor="#000099" maxcols="0" style=""><a href="http://localhost?sortcol=3;table=2;up=0#sorted_table" rel="nofollow" title="Sort by this column"><font color="#FFFFCC">Who</font></a></th>
156     <th bgcolor="#000099" maxcols="0" style=""><a href="http://localhost?sortcol=4;table=2;up=0#sorted_table" rel="nofollow" title="Sort by this column"><font color="#FFFFCC">When</font></a></th>
157     <th bgcolor="#000099" maxcols="0" style=""><a href="http://localhost?sortcol=5;table=2;up=0#sorted_table" rel="nofollow" title="Sort by this column"><font color="#FFFFCC">Progress</font></a></th>
158   </tr>
159   <tr>
160     <td bgcolor="#C8CB8F" style=""> 1 </td>
161     <td bgcolor="#C8CB8F" style=""> C </td>
162     <td bgcolor="#C8CB8F" style=""> Chose new colours </td>
163     <td bgcolor="#C8CB8F" style=""> John </td>
164     <td bgcolor="#C8CB8F" style=""> 1-Dec-02 </td>
165     <td bgcolor="#C8CB8F" style="">   </td>
166   </tr>
167   <tr>
168     <td bgcolor="#DBDDB5" style=""> 2 </td>
169     <td bgcolor="#DBDDB5" style=""> X </td>
170     <td bgcolor="#DBDDB5" style=""> Release </td>
171     <td bgcolor="#DBDDB5" style=""> John </td>
172     <td bgcolor="#DBDDB5" style=""> 1-Apr-02 </td>
173     <td bgcolor="#DBDDB5" style="">   </td>
174   </tr>
175   <tr>
176     <td bgcolor="#C8CB8F" style=""> 3 </td>
177     <td bgcolor="#C8CB8F" style="">   </td>
178     <td bgcolor="#C8CB8F" style=""> Get feedback </td>
179     <td bgcolor="#C8CB8F" style=""> Anne </td>
180     <td bgcolor="#C8CB8F" style=""> 1-Feb-02 </td>
181     <td bgcolor="#C8CB8F" style="">   </td>
182   </tr>
183   <tr>
184     <td bgcolor="#DBDDB5" style=""> 12 </td>
185     <td bgcolor="#DBDDB5" style=""> C </td>
186     <td bgcolor="#DBDDB5" style=""> Spec error handling </td>
187     <td bgcolor="#DBDDB5" style=""> Jack </td>
188     <td bgcolor="#DBDDB5" style=""> 1-Dec-02 </td>
189     <td bgcolor="#DBDDB5" style="">   </td>
190   </tr>
191   <tr>
192     <td bgcolor="#C8CB8F" style=""> 5 </td>
193     <td bgcolor="#C8CB8F" style="">   </td>
194     <td bgcolor="#C8CB8F" style=""> Abc </td>
195     <td bgcolor="#C8CB8F" style=""> John </td>
196     <td bgcolor="#C8CB8F" style="">   </td>
197     <td bgcolor="#C8CB8F" style="">   </td>
198   </tr>
199   <tr>
200     <th bgcolor="#000099" maxcols="0" style=""><span><font color="#FFFFCC"> <strong> Num </strong> </font></span></th>
201     <th bgcolor="#000099" maxcols="0" style=""><span><font color="#FFFFCC"> <strong> Status </strong> </font></span></th>
202     <th bgcolor="#000099" maxcols="0" style=""><span><font color="#FFFFCC"> <strong> Action </strong> </font></span></th>
203     <th bgcolor="#000099" maxcols="0" style=""><span><font color="#FFFFCC"> <strong> Who </strong> </font></span></th>
204     <th bgcolor="#000099" maxcols="0" style=""><span><font color="#FFFFCC"> <strong> When </strong> </font></span></th>
205     <th bgcolor="#000099" maxcols="0" style=""><span><font color="#FFFFCC"> <strong> Progress </strong> </font></span></th>
206   </tr>
207 </table>
208
209 ## <a name="Plugin Installation Instructions"></a> Plugin Installation Instructions
210
211 **Note:** You do not need to install anything on the browser to use this plugin. Below installation instructions are for the administrator who needs to install this plugin on the TWiki server.
212
213 - Download the ZIP file from the Plugin web (see below)
214 - Unzip <code>**%TOPIC%.zip**</code> in your twiki installation directory. Content: <table border="1" cellpadding="0" cellspacing="0" style="border-width: 1px">
215   <tr>
216     <th bgcolor="#6b7f93" maxcols="0" style=""><a href="http://localhost?sortcol=0;table=3;up=0#sorted_table" rel="nofollow" title="Sort by this column"><font color="#ffffff">File:</font></a></th>
217     <th bgcolor="#6b7f93" maxcols="0" style=""><a href="http://localhost?sortcol=1;table=3;up=0#sorted_table" rel="nofollow" title="Sort by this column"><font color="#ffffff">Description:</font></a></th>
218   </tr>
219   <tr>
220     <td bgcolor="#ecf2f8" style=""><code><b>data/TWiki/%TOPIC%.txt</b></code></td>
221     <td bgcolor="#ecf2f8" style=""> Plugin topic </td>
222   </tr>
223   <tr>
224     <td bgcolor="#ffffff" style=""><code><b>data/TWiki/%TOPIC%.txt,v</b></code></td>
225     <td bgcolor="#ffffff" style=""> Plugin topic repository </td>
226   </tr>
227   <tr>
228     <td bgcolor="#ecf2f8" style=""><code><b>lib/TWiki/Plugins/%TOPIC%.pm</b></code></td>
229     <td bgcolor="#ecf2f8" style=""> Plugin Perl module </td>
230   </tr>
231   <tr>
232     <td bgcolor="#ffffff" style=""><code><b>pub/TWiki/%TOPIC%/diamond.gif</b></code></td>
233     <td bgcolor="#ffffff" style=""> Diamond symbol </td>
234   </tr>
235   <tr>
236     <td bgcolor="#ecf2f8" style=""><code><b>pub/TWiki/%TOPIC%/down.gif</b></code></td>
237     <td bgcolor="#ecf2f8" style=""> Down arrow </td>
238   </tr>
239   <tr>
240     <td bgcolor="#ffffff" style=""><code><b>pub/TWiki/%TOPIC%/up.gif</b></code></td>
241     <td bgcolor="#ffffff" style=""> Up arrow </td>
242   </tr>
243 </table>
244 - Test if the plugin is correctly installed:
245   - Check above example if the table renders as expected
246   - Try click on heading to sort. Other tables should also be sortable
247
248 ## <a name="Plugin Info"></a> Plugin Info
249
250 <table border="1" cellpadding="0" cellspacing="0" style="border-width: 1px">
251   <tr>
252     <td align="right" bgcolor="#ecf2f8" style=""> Plugin Author: </td>
253     <td bgcolor="#ecf2f8" style="">[[TWiki/JohnTalintyre]], [[TWiki/PeterThoeny]]</td>
254   </tr>
255   <tr>
256     <td align="right" bgcolor="#ffffff" style=""> Plugin Version: </td>
257     <td bgcolor="#ffffff" style=""> 17 Dec 2002 </td>
258   </tr>
259   <tr>
260     <td align="right" bgcolor="#ecf2f8" style=""> Change History: </td>
261     <td bgcolor="#ecf2f8" style="">  </td>
262   </tr>
263   <tr>
264     <td align="right" bgcolor="#ffffff" style=""> 17 Dec 2002: </td>
265     <td bgcolor="#ffffff" style=""> PTh: Removed individual table Plugin settings; added TABLEATTRIBUTES Plugins setting and TABLEATTRIBUTES preferences setting </td>
266   </tr>
267   <tr>
268     <td align="right" bgcolor="#ecf2f8" style=""> 15 Dec 2002: </td>
269     <td bgcolor="#ecf2f8" style=""> PTh: Added headerrows and footerrows params (TWiki:Main/WoutMertens); added tablewidth and columnwidths params (TWiki:Main/ThorstenSommermann) </td>
270   </tr>
271   <tr>
272     <td align="right" bgcolor="#ffffff" style=""> 09 Dec 2002: </td>
273     <td bgcolor="#ffffff" style=""> PTh: Added headercolor and datacolor parameters </td>
274   </tr>
275   <tr>
276     <td align="right" bgcolor="#ecf2f8" style=""> 05 Jun 2002: </td>
277     <td bgcolor="#ecf2f8" style=""> PTh: Added "none" value to databg parameter (suggested by TWiki:Main/TaitCyrus); fixed sorting by stripping HTML tags, removing links and making sort ignore case (suggested by TWiki:Main/ShawnBradford) </td>
278   </tr>
279   <tr>
280     <td align="right" bgcolor="#ffffff" style=""> 13 Mar 2002: </td>
281     <td bgcolor="#ffffff" style=""> PTh: Added TWiki:Main/ShawnBradford 's initsort and initdirection </td>
282   </tr>
283   <tr>
284     <td align="right" bgcolor="#ecf2f8" style=""> 12 Mar 2002: </td>
285     <td bgcolor="#ecf2f8" style=""> PTh: Added valign, headeralign and dataalign; fixed bug of swapped cellpadding/cellspacing; fixed warning of uninitialized value </td>
286   </tr>
287   <tr>
288     <td align="right" bgcolor="#ffffff" style=""> 05 Jan 2002: </td>
289     <td bgcolor="#ffffff" style=""> PTh: Fixed sorting bug of cells with leading white space </td>
290   </tr>
291   <tr>
292     <td align="right" bgcolor="#ecf2f8" style=""> 06 Dec 2001: </td>
293     <td bgcolor="#ecf2f8" style=""> PTh: Fixed date sorting bug <br /> 03 Dec 2001 PTh: Fixed sort="off" bug and more </td>
294   </tr>
295   <tr>
296     <td align="right" bgcolor="#ffffff" style=""> 29 Nov 2001: </td>
297     <td bgcolor="#ffffff" style=""> PTh: Fixed Perl warnings </td>
298   </tr>
299   <tr>
300     <td align="right" bgcolor="#ecf2f8" style=""> 16 Nov 2001: </td>
301     <td bgcolor="#ecf2f8" style=""> PTh: Added table border, cell spacing, cell padding, gif files </td>
302   </tr>
303   <tr>
304     <td align="right" bgcolor="#ffffff" style=""> 07 Oct 2001: </td>
305     <td bgcolor="#ffffff" style=""> JT: Initial version </td>
306   </tr>
307   <tr>
308     <td align="right" bgcolor="#ecf2f8" style=""> CPAN Dependencies: </td>
309     <td bgcolor="#ecf2f8" style=""> none </td>
310   </tr>
311   <tr>
312     <td align="right" bgcolor="#ffffff" style=""> Other Dependencies: </td>
313     <td bgcolor="#ffffff" style=""> none </td>
314   </tr>
315   <tr>
316     <td align="right" bgcolor="#ecf2f8" style=""> Perl Version: </td>
317     <td bgcolor="#ecf2f8" style=""> 5.0 </td>
318   </tr>
319   <tr>
320     <td align="right" bgcolor="#ffffff" style=""> Plugin Home: </td>
321     <td bgcolor="#ffffff" style=""><a href="http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%" target="_top">http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%</a></td>
322   </tr>
323   <tr>
324     <td align="right" bgcolor="#ecf2f8" style=""> Feedback: </td>
325     <td bgcolor="#ecf2f8" style=""><a href="http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%Dev" target="_top">http://TWiki.org/cgi-bin/view/Plugins/%TOPIC%Dev</a></td>
326   </tr>
327 </table>
328
329 **_Related Topics:_** [[TWikiPreferences]], [[TWikiPlugins]], [[StandardColors]]
330
331 -- [[JohnTalintyre]] - 07 Oct 2001 <br /> -- [[PeterThoeny]] - 17 Dec 2002 <br />