Search code examples
phpyiicgridview

How to Display Serial Number in ascending order in CGridview in Yii without taking a extra database field


How to Display Serial Number in ascending order like

1 Record Abc
2 Record Def
3 Record Xyz

in CGridview in Yii without taking a extra database field ?


Solution

  • Hope this helps out:

    <?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'=>''
    )); ?>
    

    The $row variable is a zero-based row number