Difference between revisions of "Issue:Tablesortcol, same value in two or more rows, wrong data"

From FollowTheScore
Jump to: navigation, search
(Reply)
Line 45: Line 45:
 
$rBody.="\n|-";
 
$rBody.="\n|-";
 
</nowiki></pre>
 
</nowiki></pre>
 +
[[User:Nobodyreally|Nobodyreally]] 09:18, 30 March 2009 (UTC)

Revision as of 11:18, 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|-";

Nobodyreally 09:18, 30 March 2009 (UTC)