Get the absolute row number in the grid

In yii CGridView I can get the current row number with $ row . But this only returns the row index on the current page. I really need to get the absolute number of rows among all pages.

I use yii, so my dreams should come true β€œeasily”, so I expect that the answer should not tell me to add a special field to the data provider or to access the pager and get the current page number, and then multiply the numbers bla bla bla.

thanks

+8
yii gridview
source share
2 answers

Have you decided this? If not, I offer you the following solution

$this->widget( 'zii.widgets.grid.CGridView', array( 'columns'=>array( array( 'header'=>'No.', 'value'=>'$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)', ), ), )); 

basically you can access current pages and page size variables from a dataparauder, and you use it to calculate the row number for all the data. Why $ row + 1? because $ row starts at 0. Hope this helps: D

+28
source share

Perhaps this will help: CDataProvider has the property "totalItemCount", which can be used:

Example: $ this-> grid-> dataProvider-> getTotalItemCount ();

More details: http://www.yiiframework.com/doc/api/1.1/CDataProvider#totalItemCount-detail

0
source share

All Articles