案例1:
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'xx-xx-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'pager'=>array(
'class'=>'CLinkPager',
'nextPageLabel'=>'下一页',
'prevPageLabel'=>'上一页',
'header'=>'',
),
'summaryText'=>'显示{start}-{end}条.共{count}条记录,当前第{page}页',
'columns'=>array(
array(
'name'=>'id',
'htmlOptions'=>array('width'=>'25'),
'sortable'=>false,
),
array(
'class'=>'CButtonColumn',
'template'=>'{view} {update}',
'viewButtonOptions'=>array('title'=>'查看'),
'updateButtonOptions'=>array('title'=>'修改'),
),
array(
'class'=>'CButtonColumn',
'header'=>'首页展示',
'template'=>'{add} {del}',
'buttons'=>array(
'add' => array(
'label'=>'展示', // text label of the button
'url'=>'Yii::app()->controller->createUrl("focus/create",array("id"=>$data->primaryKey,"type"=>1))', // a PHP expression for generating the URL of the button
'imageUrl'=>'http://s.maylou.com/common/images/ysh.jpg', // image URL of the button. If not set or false, a text link is used
'options'=>array('style'=>'cursor:pointer;'), // HTML options for the button tag
'click'=>$click, // a JS function to be invoked when the button is clicked
'visible'=>'SiteRecommend::isItemInTypeAndId(1, $data->id)?false:true',
),
'del' => array(
'label'=>'取消展示', // text label of the button
'url'=>'Yii::app()->controller->createUrl("focus/delete",array("id"=>$data->primaryKey,"type"=>1))', // a PHP expression for generating the URL of the button
'imageUrl'=>'http://s.maylou.com/common/images/yzhu.jpg', // image URL of the button. If not set or false, a text link is used
'options'=>array('style'=>'cursor:pointer;'), // HTML options for the button tag
'click'=>$click, // a JS function to be invoked when the button is clicked
'visible'=>'SiteRecommend::isItemInTypeAndId(1, $data->id)?true:false',
)
),
),
),
));
?>
案例2:
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'pages-grid',
'dataProvider' => $dataProvider,
'itemsCssClass' => 'table',
'cssFile' => 'css/thead.css',
//'template'=>'{pager}{summary}{items}{pager}', //分页显示所有列的内容
'pager'=>array(
'maxButtonCount'=>'7' //最多显示几个分页页码
),
//显示指定列的内容
'columns' => array(
array(
'class'=>'CCheckBoxColumn',
'id'=>'id',
'checked'=>'$data->id==xx' //编辑选中项
),
'id',
'title',
array(
'name' => 'status',
'value' => 'Pages::model()->status($data->id)',
),
array(
'name' => 'pushtime',
'value' => 'date("Y-m-d", $data->pushtime)',
),
array(
'class' => 'CLinkColumn',
'label' => '相册', //链接显示字样
'urlExpression' => 'Yii::app()->createURL("admin/Album/admin", array("id"=>$data->id))',
),
array(
'class' => 'CButtonColumn',
'buttons'=>array('update'=>array(
'url'=>'Yii::app()->createURL("admin/product/update", array("id" =>$data->id, "status"=>"'.$status.'"))'
)), //这里可以修改update的表现形式
'deleteConfirmation'=>'确定删除这条数据吗?', //删除提示
'template' => '{update}{delete}'
),
),
));
?>
文章来源:http://currentbottle.blog.163.com/blog/static/1942941282013219435496/
http://blog.sina.com.cn/s/blog_7522019b010153f3.html