分享

YIi gridview 自定义按按钮

 gearss 2016-06-01

YIi gridview 自定义按按钮

 

我们在用表格展示数据并管理的时候,可能会需要用到按钮来操作某一行数据,比如查看,修改,删除!

Yii内置了3种按钮:查看,修改和删除,你可以自定义样式、事件。详细配置见类参考:CButtonColumn.

如果需要自定义按钮绑定指定的事件该怎么办呢?

幸运的是Yii提供了自定义按钮的办法.看代码:

在视图文件里面:

 

  1. $this->widget('zii.widgets.grid.CGridView', array(   
  2.     'id'=>'xx-xx-grid',   
  3.     'dataProvider'=>$model->search(),   
  4.     'filter'=>$model,   
  5.     'pager'=>array(   
  6.             'class'=>'CLinkPager',   
  7.             'nextPageLabel'=>'下一页',   
  8.             'prevPageLabel'=>'上一页',   
  9.             'header'=>'',   
  10.     ),   
  11.     'summaryText'=>'<font color=#0066A4>显示{start}-{end}条.共{count}条记录,当前第{page}页</font>',   
  12.     'columns'=>array(   
  13.         array(   
  14.                 'name'=>'id',   
  15.                 'htmlOptions'=>array('width'=>'25'),   
  16.                 'sortable'=>false,   
  17.         ),   
  18.         array(   
  19.             'class'=>'CButtonColumn',   
  20.             'template'=>'{view} {update}',   
  21.             'viewButtonOptions'=>array('title'=>'查看'),   
  22.             'updateButtonOptions'=>array('title'=>'修改'),   
  23.         ),   
  24.         array(   
  25.             'class'=>'CButtonColumn',   
  26.             'header'=>'首页展示',   
  27.             'template'=>'{add} {del}',   
  28.             'buttons'=>array(   
  29.                     'add' => array(   
  30.                             'label'=>'展示',     // text label of the button   
  31.                             'url'=>'Yii::app()->controller->createUrl("focus/create",array("id"=>$data->primaryKey,"type"=>1))',       // a PHP expression for generating the URL of the button   
  32.                             'imageUrl'=>'http://s./common/images/ysh.jpg',  // image URL of the button. If not set or false, a text link is used   
  33.                             'options'=>array('style'=>'cursor:pointer;'), // HTML options for the button tag   
  34.                             'click'=>$click,     // a JS function to be invoked when the button is clicked   
  35.                             'visible'=>'SiteRecommend::isItemInTypeAndId(1, $data->id)?false:true',   
  36.                     ),   
  37.                     'del' => array(   
  38.                             'label'=>'取消展示',     // text label of the button   
  39.                             'url'=>'Yii::app()->controller->createUrl("focus/delete",array("id"=>$data->primaryKey,"type"=>1))',       // a PHP expression for generating the URL of the button   
  40.                             'imageUrl'=>'http://s./common/images/yzhu.jpg',  // image URL of the button. If not set or false, a text link is used   
  41.                             'options'=>array('style'=>'cursor:pointer;'), // HTML options for the button tag   
  42.                             'click'=>$click,     // a JS function to be invoked when the button is clicked   
  43.                             'visible'=>'SiteRecommend::isItemInTypeAndId(1, $data->id)?true:false',   
  44.                     )   
  45.             ),   
  46.         ),   
  47.     ),   
  48. ));  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多