himiklab/yii2-jqgrid-widget

为 Yii2 的高效 Ajax 启用网格小部件

安装数量: 3,737

依赖项: 0

建议者: 0

安全性: 1

星标: 21

关注者: 4

分支: 15

公开问题: 0

类型:yii2-extension

1.2.3 2019-05-12 10:42 UTC

This package is auto-updated.

Last update: 2024-09-12 23:48:26 UTC


README

为强大的 Ajax 启用网格 jQuery 插件 free jqGrid 的 Yii2 包装器。

Packagist Packagist license

安装

安装此扩展的首选方式是通过 composer

  • 运行以下命令之一
php composer.phar require --prefer-dist "himiklab/yii2-jqgrid-widget" "*"

或在应用程序的 composer.json 文件的 require 部分添加

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

  • 在控制器中添加动作(可选),例如
use himiklab\jqgrid\actions\JqGridActiveAction;

public function actions()
{
    return [
        'jqgrid' => [
            'class' => JqGridActiveAction::className(),
            'model' => Page::className(),
        ],
    ];
}
  • 视图示例
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,
    ],
]) ?>

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,
    ],
]) ?>