Get the absolute row number in a grid

后端 未结 2 1700
借酒劲吻你
借酒劲吻你 2021-01-12 04:30

In yii\'s CGridView I can get the current row number by using $row. But this returns the row index within the current page only. What I rea

2条回答
  •  情歌与酒
    2021-01-12 04:55

    Have you solved 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 the currentpage and pagesize variables from the dataprovider and you use it to calculate the 'row number' for the whole data. Why the $row + 1? because $row starts from 0. Hope this helps :D

提交回复
热议问题