liyunfang/yii2-contextmenu

yii2 对 bootstrap-contextmenu 插件的扩展 https://github.com/sydcanem/bootstrap-contextmenu

安装次数: 20,792

依赖关系: 1

建议者: 0

安全性: 0

星标: 23

关注者: 5

分支: 9

公开问题: 2

类型:yii2-extension

1.0.5 2015-09-25 02:35 UTC

This package is auto-updated.

Last update: 2024-09-07 16:08:49 UTC


README

yii2 对 bootstrap-contextmenu 的扩展

yii2 对 bootstrap-contextmenu 插件的扩展 https://github.com/sydcanem/bootstrap-contextmenu

网格右键操作,您可以删除操作列

Effect picture 1

Effect picture 2

安装

安装此扩展的最佳方式是通过 composer

运行以下命令之一

 composer require --prefer-dist liyunfang/yii2-contextmenu

或在您的 composer.json 文件的 require 部分添加以下内容

"liyunfang/yii2-contextmenu": "*"

要求

此扩展需要twitter-bootstrap

使用方法

扩展安装后,只需在您的代码中通过以下方式使用它

GridView 选项

 'columns' => [
    [
        'class' => \liyunfang\contextmenu\SerialColumn::className(),
        'contextMenu' => true,
        //'contextMenuAttribute' => 'id',
        'template' => '{view} {update} <li class="divider"></li> {story}', 
        'buttons' => [
             'story' => function ($url, $model) {
                 $title = Yii::t('app', 'Story');
                 $label = '<span class="glyphicon glyphicon-film"></span> ' . $title;
                 $url = \Yii::$app->getUrlManager()->createUrl(['/user/story','id' => $model->id]);
                 $options = ['tabindex' => '-1','title' => $title, 'data' => ['pjax' => '0' ,  'toggle' => 'tooltip']];
                 return '<li>' . Html::a($label, $url, $options) . '</li>' . PHP_EOL;
              }
         ],
   ],
    ....
],
'rowOptions' => function($model, $key, $index, $gird){
     $contextMenuId = $gird->columns[0]->contextMenuId;
     return ['data'=>[ 'toggle' => 'context','target'=> "#".$contextMenuId ]];
 },

或使用 KartikSerialColumn,但需要安装 grid Kartik 扩展。请参阅 https://github.com/kartik-v/yii2-grid

GridView 选项

 'columns' => [
    [
        'class' => \liyunfang\contextmenu\KartikSerialColumn::className(),
        'contextMenu' => true,
        //'contextMenuAttribute' => 'id',
        //'template' => '{view} {update}', 
        'contentOptions'=>['class'=>'kartik-sheet-style'],
        'headerOptions'=>['class'=>'kartik-sheet-style'],
        'urlCreator' => function($action, $model, $key, $index) { 
                if('update' == $action){
                    return \Yii::$app->getUrlManager()->createUrl(['/user/index','id' => $model->id]);
                }
                if('view' == $action){
                    return \Yii::$app->getUrlManager()->createUrl(['/user/view','id' => $model->id]);
                }
                return '#'; 
        },
   ],
    ....
],
'rowOptions' => function($model, $key, $index, $gird){
     $contextMenuId = $gird->columns[0]->contextMenuId;
     return ['data'=>[ 'toggle' => 'context','target'=> "#".$contextMenuId ]];
 },

该扩展为 grid 行右击菜单,可以省去操作列。提供了继承 yii2 grid 的 SerialColumn 和继承 Kartik grid 的 SerialColumn。