Smart Row-Count In Cgridview

Hello,

I have a CGridview that lists swimmers and their racetimes in events. The times are sorted by the best times first.

At the moment im using $row to get the order of the swimmers




array(

    'header'=>'Nr',

    'value'=>'$this->grid->dataProvider->pagination->currentPage*$this->grid->dataProvider->pagination->pageSize + $row+1',

        ),



It works, but if a swimmer has the same time as another swimmer, I want them to have the the same number.

See example below.




| NR | Name      | Time     |

+----+-----------+----------+

| 1  | Person1   | 30,8     |

| 2  | Person2   | 31,2     |

| 3  | Person3   | 32,1     |

| 3  | Person4   | 32,1     |

| 5  | Person5   | 33,9     |




Any ideas on how to accomplish this?

Dear Adde

create a public method in Swimmer Model.




public function displayPosition()


{

    $times=Yii::app()->db->createCommand()

			  ->select('time')

			  ->from('swimmer')

			  ->queryColumn(); //It will bring all the times in array format.

			

			$position=1;

			foreach($times as $time)

                                {

				if($time>$this->time)

				++$position;

				}

		 

		 return $position;

}



Modify the data column in admin.php





array(

    'header'=>'Nr',

    'value'=>'$data->displayPosition()',

        ),



You can see this post, especially comment #12

It shows how to do it at your query level, it should be faster I guess

Thanks! will give it a shot! (can’t try it now tho)