Yii框架zii.widgets.grid自定义按钮

案例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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值