himiklab/yii2-jqgrid-widget

A powerful ajax-enabled grid widget for Yii2

Installs: 3 766

Dependents: 0

Suggesters: 0

Security: 1

Stars: 21

Watchers: 4

Forks: 15

Open Issues: 0

Type:yii2-extension

1.2.3 2019-05-12 10:42 UTC

This package is auto-updated.

Last update: 2024-12-13 00:16:09 UTC


README

Yii2 wrapper for a powerful ajax-enabled grid free jqGrid jQuery plugin.

Packagist Packagist license

Installation

The preferred way to install this extension is through composer.

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

or add

"himiklab/yii2-jqgrid-widget" : "*"

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

  • Add action in the controller (optional), for example:
use himiklab\jqgrid\actions\JqGridActiveAction;

public function actions()
{
    return [
        'jqgrid' => [
            'class' => JqGridActiveAction::className(),
            'model' => Page::className(),
        ],
    ];
}
  • View's example:
use himiklab\jqgrid\JqGridWidget;
use yii\helpers\Url;

<?= JqGridWidget::widget([
    'requestUrl' => Url::to('jqgrid'),
    'gridSettings' => [
        'colNames' => ['ID', 'Title', 'Author', 'Language'],
        'colModel' => [
            [
                'name' => 'id', 'index' => 'id',
                'formatter' => 'integer',
                'searchoptions' => [
                    'searchhidden' => true,
                    'sopt' => ['eq', 'ne', 'lt', 'le', 'gt', 'ge', 'nu', 'nn'],
                ],
                'hidden' => false, 'editable' => false
            ],
            [
                'name' => 'title', 'index' => 'title',
                'searchoptions' => [
                    'searchhidden' => true,
                    'sopt' => ['cn', 'nc', 'bw', 'bn', 'eq', 'ne', 'ew', 'en', 'nu', 'nn'],
                ],
                'hidden' => false, 'editable' => true
            ],
            [
                'name' => 'author', 'index' => 'author',
                'searchoptions' => [
                    'searchhidden' => true,
                    'sopt' => ['cn', 'nc', 'bw', 'bn', 'eq', 'ne', 'ew', 'en', 'nu', 'nn'],
                ],
                'hidden' => false, 'editable' => true
            ],
            [
                'name' => 'language', 'index' => 'language',
                'formatter' => 'select',
                'stype' => 'select',
                'edittype' => 'select',
                'searchoptions' => [
                    'clearSearch' => false,
                    'searchhidden' => true,
                    'value' => ':;en:English;ru:Русский;cn:汉语',
                    'sopt' => ['eq', 'ne', 'nu', 'nn'],
                ],
                'editoptions' => ['value' => [
                    'en' => 'English',
                    'ru' => 'Русский',
                    'cn' => '汉语',
                ]],
                'hidden' => false, 'editable' => true
            ],
        ],
        'rowNum' => 30,
        'rowList' => [30, 60, 90],
        'autowidth' => true,
        'multiselect' => true,
        'multiSort' => true,
        'rownumbers' => true,
        'viewrecords' => true,
        'cmTemplate' => ['autoResizable' => true],
        'autoresizeOnLoad' => true,
    ],
    'pagerSettings' => [
        'edit' => true,
        'add' => true,
        'del' => true,
        'search' => [
            'multipleSearch' => true,
            'multipleGroup' => true,
            'closeAfterSearch' => true,
            'showQuery' => true,
        ]
    ],
    'enableFilterToolbar' => true,
    'enableColumnChooser' => true,
    'filterToolbarSettings' => [
        'stringResult' => true,
    ],
]) ?>

or

use app\models\Page;
use himiklab\jqgrid\JqGridHelper;
use himiklab\jqgrid\JqGridWidget;
use yii\helpers\Url;

<?php
$columns = [
    'id' => ['type' => 'integer',],
    'title',
    'author',
    'language' => [
        'type' => 'list',
        'data' => Page::getAllLanguages(),
    ],
    'visible' => ['type' => 'boolean',],
];

$columnsIsVisible = ['id', 'title', 'author', 'language', 'visible',];
$columnsIsEditable = ['title', 'author', 'language', 'visible',];

echo JqGridWidget::widget([
    'requestUrl' => Url::to('jqgrid'),
    'gridSettings' => [
        'colNames' => ['ID', 'Title', 'Author', 'Language', 'Visible'],
        'colModel' => JqGridHelper::jqgridColModel($columns, $columnsIsVisible, $columnsIsEditable),
        'rowNum' => 30,
        'rowList' => [30, 60, 90],
        'autowidth' => true,
        'multiselect' => true,
        'multiSort' => true,
        'rownumbers' => true,
        'viewrecords' => true,
        'cmTemplate' => ['autoResizable' => true],
        'autoresizeOnLoad' => true,
    ],
    'pagerSettings' => [
        'edit' => true,
        'add' => true,
        'del' => true,
        'search' => [
            'multipleSearch' => true,
            'multipleGroup' => true,
            'closeAfterSearch' => true,
            'showQuery' => true,
        ]
    ],
    'enableFilterToolbar' => true,
    'enableColumnChooser' => true,
    'filterToolbarSettings' => [
        'stringResult' => true,
    ],
]) ?>