himiklab/yii2-gridview-ajaxed-widget Improved Yii2 GridView widget with support ajax, pjax and modal (Bootstrap)

Ajaxed GridView Widget for Yii2

  1. Installation
  2. Usage

Improved Yii2 GridView widget with support ajax, pjax and modal (Bootstrap).

Packagist Packagist license

Installation

The preferred way to install this extension is through composer.

  • Either run
php composer.phar require --prefer-dist "himiklab/yii2-gridview-ajaxed-widget" "*"

or add

"himiklab/yii2-gridview-ajaxed-widget" : "*"

to the require section of your application's composer.json file.

Usage

// index.php
use himiklab\yii2\ajaxedgrid\GridView;

GridView::widget([
    'dataProvider' => $dataProvider,
    'columns' => [
        'title',
        'author',
        'language',
        'visible:boolean',
    ],
    'jsErrorCallback' => 'function(jqXHR, textStatus) {console.log(jqXHR, textStatus, errorThrown)}',
]);
// _form.php
    <?php $form = ActiveForm::begin(['id' => 'test-form']); ?>

    <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'author')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'language')->dropDownList($model::getAllLanguages()) ?>

    <?= $form->field($model, 'visible')->checkbox() ?>

    <div class="form-group">
        <?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
    </div>

    <?php ActiveForm::end(); ?>
// controller
    public function actionIndex()
    {
        $dataProvider = new ActiveDataProvider([
            'query' => Page::find(),
        ]);

        return $this->render('index', [
            'dataProvider' => $dataProvider,
        ]);
    }

    public function actionCreate()
    {
        $model = new Page();
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return null;
        }

        return $this->renderAjax('_form', [
            'model' => $model,
        ]);
    }

    public function actionUpdate($id)
    {
        $model = $this->findModel($id);
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return null;
            //return '#reload';
            //return '#alert OK!';
            //return '#redirect /';
            //return '#file document.txt ' . \base64_encode('document content');
        }

        return $this->renderAjax('_form', [
            'model' => $model,
        ]);
    }

    public function actionDelete($id)
    {
        $this->findModel($id)->delete();
    }

    protected function findModel($id)
    {
        if (($model = Page::findOne($id)) === null) {
            throw new NotFoundHttpException('Page not found.');
        }

        return $model;
    }

It's all!

1 0
2 followers
29 downloads
Yii Version: 2.0
License: MIT
Category: User Interface
Developed by: himiklab
Created on: Oct 23, 2018
Last updated: (not set)
Packagist Profile
Github Repository

Related Extensions