PHP code example of himiklab / yii2-gridview-ajaxed-widget

1. Go to this page and download the library: Download himiklab/yii2-gridview-ajaxed-widget library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

himiklab / yii2-gridview-ajaxed-widget example snippets


// 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
     $form = ActiveForm::begin(['id' => 'test-form']); 

// 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;
    }

php composer.phar