Giter Site home page Giter Site logo

yii2-actionbar's Introduction

ActionBar

ActionBar is a Yii 2 widget that render the drop-down list for manipulation selected the GridView items and control buttons. The widget permits you to fully customize elements.

Screenshot

Installation

You can install the widget using Composer. Just run the following command under your application folder:

php composer.phar require --prefer-dist mickgeek/yii2-actionbar

Usage

use mickgeek\actionbar\Widget as ActionBar;

<?= ActionBar::widget([
    'grid' => 'user-grid',
]) ?>

But first, add the action to your controller:

public function actions()
{
    return [
        'delete-multiple' => [
            'class' => 'mickgeek\actionbar\DeleteMultipleAction',
            'modelClass' => 'app\models\User',
        ],
    ];
}

Note: You can write your action without using DeleteMultipleAction class.

Tip: For information about properties and methods of the widget, see the bundled DOCUMENTATION.md.

Examples

Below are two examples showing some features of the widget.

Advanced Bulk Actions

Advanced Bulk Actions Screenshot

The code in the view:

use yii\helpers\Url;
use mickgeek\actionbar\Widget as ActionBar;

<?= ActionBar::widget([
    'grid' => 'user-grid',
    'templates' => [
        '{bulk-actions}' => ['class' => 'col-xs-4'],
        '{create}' => ['class' => 'col-xs-8 text-right'],
    ],
    'bulkActionsItems' => [
        'Update Status' => [
            'status-active' => 'Active',
            'status-blocked' => 'Blocked',
        ],
        'General' => ['general-delete' => 'Delete'],
    ],
    'bulkActionsOptions' => [
        'options' => [
            'status-active' => [
                'url' => Url::toRoute(['update-status', 'status' => 'active']),
                'disabled' => !Yii::$app->user->can('updateUserStatus'),
            ],
            'status-blocked' => [
                'url' => Url::toRoute(['update-status', 'status' => 'blocked']),
                'disabled' => !Yii::$app->user->can('updateUserStatus'),
            ],
            'general-delete' => [
                'url' => Url::toRoute('delete-multiple'),
                'data-confirm' => 'Are you sure?',
                'disabled' => !Yii::$app->user->can('deleteUser'),
            ],
        ],
        'class' => 'form-control',
    ],
]) ?>

The code in the User controller:

public function actions()
{
    return [
        'delete-multiple' => [
            'class' => 'mickgeek\actionbar\DeleteMultipleAction',
            'modelClass' => 'app\models\User',
            'beforeDeleteCallback' => function ($action) {
                if (!Yii::$app->user->can('deleteOwnAccount', Yii::$app->getRequest()->post('ids'))) {
                    Yii::$app->getSession()->setFlash('error', 'You cannot delete your own account.');

                    $action->redirect();
                    Yii::$app->end();
                }
            },
            'afterDeleteCallback' => function ($action) {
                Yii::$app->getSession()->setFlash('success', 'The selected users have been deleted successfully.');
            },
        ],
    ];
}

public function actionUpdateStatus($status)
{
    ...
}

Custom Buttons

Custom Buttons Screenshot

The code:

use mickgeek\actionbar\Widget as ActionBar;

/* @var $model app\models\User */
<?= ActionBar::widget([
    'templates' => [
        '{back}' => ['class' => 'col-xs-4'],
        '{update} {delete}' => ['class' => 'col-xs-8 text-right'],
    ],
    'elements' => [
        'back' => Html::a(
            '<span class="glyphicon glyphicon-chevron-left"></span> ' . 'Back',
            ['/users/index'],
            ['class' => 'btn btn-default']
        ),
        'update' => Html::a(
            '<span class="glyphicon glyphicon-pencil"></span> ' . 'Update',
            ['/users/update', 'id' => $model->id],
            ['class' => 'btn btn-default']
        ),
        'delete' => Html::a(
            '<span class="glyphicon glyphicon-trash"></span> ' . 'Delete',
            ['/users/delete', 'id' => $model->id],
            ['class' => 'btn btn-default']
        ),
    ],
]) ?>

License

This extension is released under the BSD 3-Clause License. See the bundled LICENSE.md for details.

yii2-actionbar's People

Contributors

aleksandrivin avatar execut avatar mickgeek avatar neatlife avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

yii2-actionbar's Issues

Составной ключ в колонке чекбоксов

form.append('<input type=\"hidden\" name=\"' + (options.getAttribute('name') ? options.getAttribute('name') : 'ids') + '[]\" value=' + id + ' />');

В случае если ключ составной при формировании виртуальной формы получаем вот такое https://w6p.ru/NDMwYW.png

В ядре в value CheckboxColumn пишется Json, но при получении выделенных строк выдается массив из объектов. Нужно обратно делать JSON_ENCODE
https://github.com/yiisoft/yii2/blob/20aa5080189cbacd4180d3b115752817921eb364/framework/grid/CheckboxColumn.php#L123

yii\grid\CheckboxColumn filter row selected.

Hi, extencion excellent, I would like to filter the gridview by yii\grid\CheckboxColumn rows selected this is possible with your extension, that form could be done and thank you very much in advance for your answer,

Thks,

Wilmer.

Не работает js: form.submit();

В firefox 48.0, ubuntu 16 не срабатывает js код form.submit();
Консоль ошибок не выдает но пост запрос не отправляется.
Обошел таким путем:
form.submit(); в файле Widget.php
заменил на
$('body').append(form);
form.submit();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.