Yii Framework Forum: can Yii override sorting - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

can Yii override sorting Rate Topic: -----

#1 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 752
  • Joined: 02-February 09

Posted 05 January 2010 - 11:55 AM

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
0

#2 User is offline   sebas 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 497
  • Joined: 28-October 08
  • Location:Buenos Aires, Argentina

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!! :D
0

#3 User is offline   jayrulez 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 348
  • Joined: 29-July 09

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.
0

#4 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 752
  • Joined: 02-February 09

Posted 05 January 2010 - 01:16 PM

Brilliant...looks like both solutions solved the situation. Cheers mates!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users