Yii2 wrapper for a powerful ajax-enabled grid free jqGrid jQuery plugin., (*1)
, (*2)
Installation
The preferred way to install this extension is through composer., (*3)
php composer.phar require --prefer-dist "himiklab/yii2-jqgrid-widget" "*"
or add, (*4)
"himiklab/yii2-jqgrid-widget" : "*"
to the require section of your application's composer.json
file., (*5)
- Add action in the controller (optional), for example:
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,
],
]) ?>
or, (*6)
use app\models\Page;
use himiklab\jqgrid\JqGridHelper;
use himiklab\jqgrid\JqGridWidget;
use yii\helpers\Url;
['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,
],
]) ?>