Monday, March 5, 2012

Make page numbering in CGridview yii framework

This time I want to share how we can easily modify CGridView based on the table shown to add automatic numbering of CGridView.

Let's take a look how we can set up this with little modification :
See the example below :


$this->widget('zii.widgets.grid.CGridView',array(
   'dataProvider'=>$provider,
   'id'=>'components-id',
   'columns'=>array(
     array(
      'name'=>'No',
      'type'=>'raw',
      'value'=>'$this->grid->dataProvider->pagination->currentPage*$this->grid->dataProvider->pagination->pageSize + $row+1'//this is the numbering of your cgridview
      ),
     array(
      'name'=>'Name',
      'type'=>'raw',
      'value'=>'Chtml::link(Chtml::encode($data->name),array("risk/view","id"=>$data->risk_id))'
      ),
     array(
      'name'=>'Date Identified',
      'type'=>'raw',
      'value'=>'Chtml::encode($data->date_identified)'
      ),
     array(
      'name'=>'description',
      'type'=>'raw',
      'value'=>'Chtml::encode($data->description)'
      ),
     
    )
   
 ));

Voila now we can see an automatic number in your CGridView..

No comments:

Post a Comment