June 23 2013

Yii CGridView auto increase row number

Tagged Under :

Yii
Below example showing you how to add the row number in cgridview widgets.

You just need add the following script inside the array columns.
array(
	'header' => 'No.',
	'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)',
),

The completed example as below:
$this->widget('zii.widgets.grid.CGridView', array(
        'id' => 'grid-row-number',
        'dataProvider' => $model->search(),
        'filter' => $model,
        'columns' => array(
				array(
					'header' => 'No.',
					'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)',
				),
                'name',
                'create_time'
		)
));

Make a Comment

You must be logged in to post a comment.