More information about this topic
Reset database
 | 
GridView with CArrayDataProvider
Displaying 1-2 of 2 results.
usernameemail
fromarray
test 2hello@example.com

protected/modules/UiModule/views/dataview/grid_view_array.php

$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"]))',
		),
	),
));

protected/modules/UiModule/controllers/DataviewController.php

 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);
	}
Fork me on GitHub