Yii: CListview sorting by a dynamic model attribute

80 Views Asked by At

I have a CListview which displays a list of products. I need to sort that list using location of the product. Product model has method getDistance() which calculates the distance between user and the product. Is there an easy way to achive that using CSort?

1

There are 1 best solutions below

0
On BEST ANSWER

If you are using CActiveDataProvider as data provider in your CListView then you must calculate same distance value in SQL query (to be able to compare and sort). If this is complicated, you can switch to CArrayDataProvider. where you can do your complex calculations and set them to model attributes.