Home > yii framework > Using CArrayDataProvider

Using CArrayDataProvider

View

$this->widget('zii.widgets.grid.CGridView', array(
	    'dataProvider' => $arrayDataProvider,
	    'columns' => array(
	        array(
	            'name' => 'username',
	            'type' => 'raw',
	            'value' => 'CHtml::encode($data["username"])'
	        ),
	        array(
	            'name' => 'email',
	            'type' => 'raw',
	            'value' => 'CHtml::link(CHtml::encode($data["email"]), "mailto:".CHtml::encode($data["email"]))',
	        ),
	    ),
	));


Controller
public function actionGridViewArray() {
	 
	   $rawData=array(
           array('id'=>1, 'username'=>'from', 'email'=>'array'),
	           array('id'=>2, 'username'=>'test 2', 'email'=>'hello@example.com'),
	       );
	       // or using: $rawData=User::model()->findAll();
	       $arrayDataProvider=new CArrayDataProvider($rawData, array(
	           'id'=>'id',
	           /* 'sort'=>array(
	               'attributes'=>array(
	                   'username', 'email',
	               ),
	           ), */
	           'pagination'=>array(
	               'pageSize'=>10,
	           ),
	       ));
	 
	       $params =array(
	           'arrayDataProvider'=>$arrayDataProvider,
	       );
	 
	       if(!isset($_GET['ajax'])) $this->render('grid_view_array', $params);
	       else  $this->renderPartial('grid_view_array', $params);
	   }

Advertisement
Categories: yii framework
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.