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

From FollowTheScore
Jump to: navigation, search
(New page: {{Issue |Type = Bug <-- please select |Extension = DPL <-- please select |Version = ? |Description = using tablesortcol when there is same value in several rows results in...)
 
(Solved)
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{Issue
 
{{Issue
  |Type        = Bug <-- please select
+
  |Type        = Bug  
  |Extension  = DPL <-- please select
+
  |Extension  = DPL  
  |Version    = ?
+
  |Version    = 1.7.4
 
  |Description = using tablesortcol when there is same value in several rows results in discarded rows
 
  |Description = using tablesortcol when there is same value in several rows results in discarded rows
 
  |Status      = open
 
  |Status      = open
Line 8: Line 8:
  
 
== Problem ==
 
== 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, where also the ''distinct'' parameter is tested:
+
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 [http://www.usnb.it/wiki/index.php?title=Test:DPLSort] , where also the ''distinct'' parameter is tested.
[http://www.usnb.it/wiki/index.php?title=Test:DPLSort]
 
 
It seems a bug, but probably this can be related to my low experience in DPL...
 
It seems a bug, but probably this can be related to my low experience in DPL...
  
 
== 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 && 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|-";
 +
</nowiki></pre>
 +
 +
[[User:Nobodyreally|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? --[[User:Briotti|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. [[User:Nobodyreally|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. [[User:Nobodyreally|Nobodyreally]] 03:55, 31 March 2009 (UTC)
 +
:::OK, thanks again... --[[User:Briotti|GB]] 08:56, 31 March 2009 (UTC)

Latest revision as of 10:56, 31 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 && 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)
OK, thanks again... --GB 08:56, 31 March 2009 (UTC)