Basic GridView example
rotected/modules/UiModule/views/dataview/grid_view.php
$this->widget('zii.widgets.grid.CGridView', array( 'dataProvider' => $model->search(), 'filter' => $model, '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/models/User.php
public function search() { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria=new CDbCriteria; $criteria->compare('username',$this->username,true); $criteria->compare('email',$this->email,true); return new CActiveDataProvider(get_class($this), array( 'criteria'=>$criteria, 'sort'=>array( 'defaultOrder'=>'username ASC', ), 'pagination'=>array( 'pageSize'=>5 ), )); }
protected/modules/UiModule/controllers/DataviewController.php
public function actionGridView() { $model =new User('search'); if(isset($_GET['User'])) $model->attributes =$_GET['User']; $params =array( 'model'=>$model, ); if(!isset($_GET['ajax'])) $this->render('grid_view', $params); else $this->renderPartial('grid_view', $params); }