01042: Implementation of $TableRowAttrFmt is inconsistent in coloring even/odd rows

Summary: Implementation of $TableRowAttrFmt is inconsistent in coloring even/odd rows
Created: 2008-08-28 14:32
Status: Closed - not a bug
Category: Bug
From: bwills?
Assigned:
Priority: 42
Version: 2.2.0-beta65
OS: OS: RHEL ES 4.0/Apache 2.0.52/PHP 4.3.9

Description: Implementation of $TableRowAttrFmt is inconsistent in coloring even/odd rows

Reference recipe: FormattingTables

Recipe excerpt: an administrator might choose to give each row a unique class attribute by row number: $TableRowAttrFmt = "class='row\$TableRowCount'";

This code functions correctly as far as alternating row color is concerned, but does not preserve cosmetics in a special case. When a table has an odd number of rows the even/odd row coloring will switch for subsequent tables on the same page. For short tables this is actually quite an eyesore because row 1 will visually clash with the header row.

This problem is due to loose management of the static variable $rowcount, in function FormatTableRow, file pmwiki.php, which maintains the even/odd row state across function calls.

Small changes to two files in the wiki core corrected this issue at my site:

$ diff pmwiki.php.orig pmwiki.php
1339c1339
< function FormatTableRow($x, $sep = '\\|\\|') {
---
> function FormatTableRow($x, $sep = '\\|\\|', $reset_count = false) {
1342a1343,1346
>   if ($reset_count) {
>     $rowcount = 0;
>     return '';
>   }
$ diff stdmarkup.php.orig  stdmarkup.php
375c375
<     .'<:block,1>'");
---
>     .'<:block,1>'.FormatTableRow(0,0,true)");

Hi. I seem unable to reproduce this bug, all tables start with a green row. Maybe you need to use $TableRowIndex instead of $TableRowCount to have repeating alternate styles? --Petko June 15, 2009, at 08:44 AM