[TYPO3-formidable] renderlet:LISTER - Wrong sort order - Columns with numeric values get sorted wrong. I.e. 1, 15, 2, 3 instead of 1, 2, 3, 15

Uwe Schmelzer us at dvschmelzer.de
Tue Apr 20 01:22:58 CEST 2010


Hi list,

I've just posted this to the bugtracker:
http://bugs.typo3.org/view.php?id=14156

Short version:

PROBLEM:
renderlet:LISTER - Wrong sort order - Columns with numeric values get 
sorted wrong. I.e. 1, 15, 2, 3 instead of 1, 2, 3, 15


SOLUTION:
4.1 Quick and dirty solution
-------------------------------
File:
----------------
EXT:ameos_formidable/api/base/ds_phparray/api/class.tx_dsphparray.php

Line:
----------------
57ff.

Always call these function with flag SORT_NUMERIC

$flags = SORT_NUMERIC;
arsort($named_hash, $flags);
...
$flags = SORT_NUMERIC;
asort($named_hash, $flags);


4.2 Better solution
-------------------------------
Add sorting property for each col in renderlet:LISTER

For columns with numeric content
	/columns/column/sort_mode = SORT_NUMERIC

For columns with string content
	/columns/column/sort_mode = SORT_STRING
	
Just like the Constants defined in the php manual
for sort(). See http://php.net/manual/en/function.sort.php	


cheers Uwe Schmelzer






********* LONG VERSION ***********

renderlet:LISTER - Wrong sort order - Columns with numeric values get 
sorted wrong. I.e. 1, 15, 2, 3 instead of 1, 2, 3, 15

1. Version
===========================================================
formidable v2.0.4.21
php 5.2


2. Example
===========================================================
A renderlet:LISTER with some columns.
E.g. col1: houses and col2: number of rooms in the house.

Data:
houses;rooms;
----------------
house_A;1;
house_B;2;
house_C;3;
house_D;15;


1.1 If you click on the col-Name to start ASC sorting, you get a "wrong" 
order:

Sort-Result:
----------------
house_A;1;
house_D;15; (Wrong order, should be last item)
house_B;2;
house_C;3;


1.2 If you click on the col-Name to start DESC sorting, you get a 
"wrong" order:

Sort-Result:
----------------
house_C;3;
house_B;2;
house_D;15; (Wrong order, should be first item)
house_A;1;



3. Cause
===========================================================

File:
----------------
EXT:ameos_formidable/api/base/ds_phparray/api/class.tx_dsphparray.php

Line:
----------------
57ff.

arsort($named_hash, $flags=0);
...
asort($named_hash, $flags=0);


Explanation
----------------
The sorting is done here.
The sort functions are called without flags.
Thus using the default sorting order "SORT_REGULAR"




4. SOLUTION
===========================================================

4.1 Quick and dirty solution
-------------------------------
Always call the function with flag SORT_NUMERIC

$flags = SORT_NUMERIC;
arsort($named_hash, $flags);
...
$flags = SORT_NUMERIC;
asort($named_hash, $flags);


4.2 Better solution
-------------------------------
Add sorting property for each col in renderlet:LISTER

For columns with numeric content
	/columns/column/sort_mode = SORT_NUMERIC

For columns with string content
	/columns/column/sort_mode = SORT_STRING
	
Just like the Constants defined in the php manual
for sort(). See http://php.net/manual/en/function.sort.php	



More information about the TYPO3-project-formidable mailing list