CGridView的功能是用来显示的数据列表。它支持排序,分页,和AJAX数据请求。
css
CGridView最好使用 data provider,最好是 CActiveDataProvider 。
html
$dataProvider=new CActiveDataProvider('Post'); $this->widget('zii.widgets.grid.CGridView', array( 'dataProvider'=>$dataProvider, ));
$this->widget('zii.widgets.grid.CGridView', array( 'dataProvider'=>$dataProvider, 'columns'=>array( 'title', // display the 'title' attribute 'category.name', // display the 'name' attribute of the 'category' relation 'content:html', // display the 'content' attribute as purified HTML array( // display 'create_time' using an expression 'name'=>'create_time', 'value'=>'date("M j, Y", $data->create_time)', ), array( // display 'author.username' using an expression 'name'=>'authorName', 'value'=>'$data->author->username', ), array( // display a column with "view", "update" and "delete" buttons 'class'=>'CButtonColumn', ), ), ));
actionPrefix 方法前辍ajax
afterAjaxUpdate AJAX成功响应后调用的JAVASCRIPT函数express
ajaxUpdate 是否启用AJAX请求数据api
ajaxUpdateError AJAX失败响应后调用的JAVASCRIPT函数yii
ajaxUrl AJAX请求的URLide
ajaxVar AJAX请求,使用GET方式传送的变量函数
baseScriptUrl 视图资源的URLthis
beforeAjaxUpdate 在AJAX调用以前调用的JAVASCRIPT函数spa
blankDisplay 列标题为空显示的内容
columns 内容列有配置
controller 控制器
cssFile 视图的样式
dataProvider 视图的数据
emptyText 内容为空显示的信息
filterPosition 搜索框所在的位置