问题描述
在yii的 CGridView 中,我可以使用 $ row 获取当前行号。但是,这仅返回当前页面内的行索引。我真正需要的是在所有页面中获得绝对的行号。
我使用yii,所以我的梦想应该容易实现,所以我期望答案不应该引导我向数据提供者添加一个特殊字段,或者访问寻呼机并获取当前页码,然后乘以数字bla bla bla。
谢谢
你解决了这个问题吗?如果不是,我为您提供以下解决方案:
$ this->小部件(
'zii.widgets.grid .CGridView',
array(
'columns'=> array(
array(
'header'=>'No。',
'value' = $ this-> grid-> dataProvider-> pagination-> currentPage * $ this-> grid-> dataProvider-> pagination-> pageSize +($ row + 1)',
),
),
));
基本上,您可以访问dataprovider中的当前页面和pagesize变量,并使用它来计算'row数字'为整个数据。为什么$ row + 1?因为$行从0开始。希望这有助于:D
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
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
这篇关于获取网格中的绝对行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!