Get the absolute row number in a grid

让人想犯罪 __ 提交于 2019-12-19 05:53:05

问题


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 really need is to get the absolute row number among all pages.

I am using yii, so my dreams should come true "easily", so I expect the answer should not guide me to add a special field to the data provider or access the pager and get the current page number and then multiply numbers bla bla bla.

Thanks


回答1:


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




回答2:


Maybe this will help: CDataProvider has a property "totalItemCount" which can be used:

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

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



来源:https://stackoverflow.com/questions/5834522/get-the-absolute-row-number-in-a-grid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!