2

如何按升序显示序列号,例如

1 Record Abc
2 Record Def
3 Record Xyz

在 Yii 中的 CGridview 中无需额外的数据库字段?

4

3 回答 3

6

它也适用于分页

$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
    )
于 2013-12-19T04:20:09.353 回答
3

希望这会有所帮助:

<?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变量是从零开始的行号

于 2013-09-30T11:49:18.467 回答
0

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
    )
于 2016-08-12T04:04:55.243 回答