Issue:Tablesortcol, same value in two or more rows, wrong data
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 && strlen($row) > 0) { $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.="\n|-".$rows[$index]; $rBody.="\n|-";
Nobodyreally 09:18, 30 March 2009 (UTC)
Solved
TKS a lot! It works now... Just a last question: this kind of patch will be apply to the next DPL release or I'll need to patch again? --GB 20:39, 30 March 2009 (UTC)
- No clue, I just found the issue when I needed it and thought I would post my solution. I hope it is included in later versions if it really was not designed to function this way. Nobodyreally 03:05, 31 March 2009 (UTC)
- I just changed the code above slightly (so add it again GB), it will sort rows even if the sort column's row is blank. Nobodyreally 03:55, 31 March 2009 (UTC)