YIi gridview 自定义按按钮
2013-06-09 00:29
465 查看
Yii框架zii.widgets.grid自定义按钮,ajax触发事件并提示
博客分类:PHP
我们在用表格展示数据并管理的时候,可能会需要用到按钮来操作某一行数据,比如查看,修改,删除!
Yii内置了3种按钮:查看,修改和删除,你可以自定义样式、事件。详细配置见类参考:CButtonColumn.
如果需要自定义按钮绑定指定的事件该怎么办呢?
幸运的是Yii提供了自定义按钮的办法.看代码:
在视图文件里面:
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'=>'<font color=#0066A4>显示{start}-{end}条.共{count}条记录,当前第{page}页</font>',
'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',
)
),
),
),
));
相关文章推荐
- Yii::使用GridView::widget 定义系统增删改查按钮,和自定义按钮
- Yii::使用GridView::widget 定义系统增删改查按钮,和自定义按钮
- yii, gridview隐藏查看view按钮以及自定义查看按钮链接
- yii2.0之GridView自定义按钮和链接用法
- yii2.0之GridView自定义按钮和链接用法
- Gridview添加自定义删除按钮
- gridview 自定义按钮 如何取得当前行的得数据,或者关键字段的方法
- 调整 ASPxGridView 中的分页按钮自定义输出
- ASP.NET中GridView自定义按钮触发事件
- GridView操作小技巧-自定义删除按钮
- Yii框架zii.widgets.grid自定义按钮,ajax触发事件并提示
- gridview控件自定义绑定,响应模板列按钮事件
- GridView中自定义单选按钮列的实现!
- GridView中自定义单选按钮列的实现!(修改)
- DevExpress GridView 自定义搜索按钮改为中文内容
- 在GridView中自定义删除按钮,加入Javasript的方法
- Yii2.0中在GridView添加字体图标按钮
- Yii CGridView CButtonColumn, ajax 自定义按钮之三
- Yii框架中GridView按钮调用JS
- Yii CGridView CButtonColumn, 自定义按钮之二