RESOLVED!
Hi
I have a query that orders the results via $criteria->sort="param1 ASC"; When the application loads the respective action all is sorted...so far so good. If I however attempt to sort the results according to another attribute after the results are being displayed Yii adds another sorting parameter without removing the core declared one. So no matter how I sort afterwords all sorting becomes dependant on $criteria->sort="param1 ASC".
My question is: Is it possible to tell Yii to sort the results after they are displayed according to get parameter only and the core declared one to be used only during loading or should I extend the CSort class and add the logic myself.
Please advise.
Regards,
b
Page 1 of 1
can Yii override sorting
#2
Posted 05 January 2010 - 12:09 PM
If you are using CSort,
Did you try to use CSort::defaultOrder instead of $criteria->order???
If not, try it!!
Did you try to use CSort::defaultOrder instead of $criteria->order???
If not, try it!!
#3
Posted 05 January 2010 - 12:12 PM
You can achieve that in your controller eg:
$sortBy = isset($_GET['sortBy']) ? $_GET['sortBy'] : null;
if($sortBy===null)
{
SORT BY DEFAULT
}else{
SORT BY GET FIELD...
}
php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";
python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]
ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}
You say Tomato, I say Tomato.
#4
Posted 05 January 2010 - 01:16 PM
Brilliant...looks like both solutions solved the situation. Cheers mates!
Share this topic:
Page 1 of 1

Help














