Difference between revisions of "Issue:Tablesortcol, same value in two or more rows, wrong data"
From FollowTheScore
Nobodyreally (talk | contribs) |
|||
Line 12: | Line 12: | ||
== Reply == | == Reply == | ||
+ | Seems to be incorrectly coded or undocumented, array_values() (used by `tablesortcol`) will strip all unique keys. | ||
+ | If you need to retain all rows, replace the following text in `DynamicPageList2.php` | ||
+ | <pre><nowiki> | ||
+ | foreach($rows as $row) { | ||
+ | if (($word = explode("\n|",$row,$sortcol))!==false && count($word)>=$sortcol) { | ||
+ | $rowsKey[] = $word[$sortcol - 1]; | ||
+ | } else { | ||
+ | $rowsKey[] = $row; | ||
+ | } | ||
+ | } | ||
+ | if ($iTableSortCol<0) krsort($rowsKey); | ||
+ | else ksort ($rowsKey); | ||
+ | $rows=array_combine(array_values($rowsKey),$rows); | ||
+ | ksort($rows); | ||
+ | $rBody="\n|-".join("\n|-",$rows)."\n|-"; | ||
+ | </nowiki></pre> | ||
+ | with | ||
+ | <pre><nowiki> | ||
+ | foreach($rows as $index => $row) { | ||
+ | if (($word = explode("\n|",$row,$sortcol))!==false && count($word)>=$sortcol) { | ||
+ | $rowsKey[$index] = $word[$sortcol - 1]; | ||
+ | } else { | ||
+ | $rowsKey[$index] = $row; | ||
+ | } | ||
+ | } | ||
+ | if ($iTableSortCol<0) arsort($rowsKey); | ||
+ | else asort ($rowsKey); | ||
+ | |||
+ | $rBody="\n|-"; | ||
+ | foreach($rowsKey as $index => $val) | ||
+ | $rBody.=($val!='' ? "\n|-".$rows[$index] : ''); | ||
+ | $rBody.="\n|-"; | ||
+ | </nowiki></pre> |
Revision as of 11:16, 30 March 2009
Description: | using tablesortcol when there is same value in several rows results in discarded rows |
Extension / Version: | DPL / 1.7.4 |
Type / Status: | Bug / open |
Problem
There is something strange (or is it an expected behaviour?) when the column specificated by tablesortcol parameter contains the same value in different cells: only one row is displayed for each value, but the PAGES magic word returns the sum of all pages selected. You can see some examples at [1] , where also the distinct parameter is tested. It seems a bug, but probably this can be related to my low experience in DPL...
Reply
Seems to be incorrectly coded or undocumented, array_values() (used by `tablesortcol`) will strip all unique keys. If you need to retain all rows, replace the following text in `DynamicPageList2.php`
foreach($rows as $row) { if (($word = explode("\n|",$row,$sortcol))!==false && count($word)>=$sortcol) { $rowsKey[] = $word[$sortcol - 1]; } else { $rowsKey[] = $row; } } if ($iTableSortCol<0) krsort($rowsKey); else ksort ($rowsKey); $rows=array_combine(array_values($rowsKey),$rows); ksort($rows); $rBody="\n|-".join("\n|-",$rows)."\n|-";
with
foreach($rows as $index => $row) { if (($word = explode("\n|",$row,$sortcol))!==false && count($word)>=$sortcol) { $rowsKey[$index] = $word[$sortcol - 1]; } else { $rowsKey[$index] = $row; } } if ($iTableSortCol<0) arsort($rowsKey); else asort ($rowsKey); $rBody="\n|-"; foreach($rowsKey as $index => $val) $rBody.=($val!='' ? "\n|-".$rows[$index] : ''); $rBody.="\n|-";