如何按升序显示序列号,例如
1 Record Abc
2 Record Def
3 Record Xyz
在 Yii 中的 CGridview 中无需额外的数据库字段?
它也适用于分页
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'status-grid',
'dataProvider'=>$dataProvider,
'columns'=>array(
array(
'header'=>'SL No',
'value'=>'$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)',
),
//Other fields
)
希望这会有所帮助:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'id'=>'accounts-grid',
'columns'=>array(
array(
'header'=>'Serial Number',
'value'=>'$row+1',
),
'bank',
'branch',
'account',
array(
'class'=>'CButtonColumn',
'template'=>'{update} {delete}',
'htmlOptions'=>array('style'=>'width:40px;'),
'updateButtonUrl'=>'Yii::app()->controller->createUrl("index", array("update"=>$data->uniq_id))',
'headerHtmlOptions'=>array('style'=>'width:40px;'),
),
),
'summaryText'=>''
)); ?>
$row
变量是从零开始的行号
sort
我用and找到了更好的答案filter
。
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'status-grid',
'dataProvider'=>$dataProvider,
'columns'=>array(
array(
array(
'name'=>'id',
'value'=>'$this->grid->dataProvider->getSort()->getDirection($this->name) != "desc" ? $this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1) : $this->grid->dataProvider->pagination->itemCount - $this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize - ($row)',
),
//Other fields
)