PHP code example of mallka / yii2-risegrid
1. Go to this page and download the library: Download mallka/yii2-risegrid 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/ */
mallka / yii2-risegrid example snippets
<?= \mallka\risegrid\RiseGrid::widget([
#整个jqGrid的ID,该值将得到:
#选中行的变量:list2_lastsel;
#jqgrid的实例:{$this->render_id}_grid;
#jqgrid的实例:jqgrid ,如果一个页面有多个jqgrid的话,该值永远指向最后一个
'render_id' => 'list2',
#分类和按钮组的渲染id
'pager' => 'list2_page',
#数据加载的网址
'url' => \yii\helpers\Url::to([ 'user-backend/ajax_search' ]),
#单元格提交的网址,该值不能与editurl共存
#'cellurl'=>\yii\helpers\Url::to(['user-backend/ajax_searchaaaa']),
#行编辑提交的网址,该值不能和cellurl共存
#'editurl'=>\yii\helpers\Url::to(['user-backend/ajax_searchaaaa']),
'mk_language' => 'zh-CN',
//使用某ActiveRecord 实例
#'mk_model'=>$userBackend,
//或者自定义
'mk_model' => [
//full
[
'label' => '测试以下',
//we suggest name = index,
'name' => 'username',
'index' => 'username',
//default width is 40
'width' => 40,
'align' => 'left',
#是否主键
'key' => false,
#隐藏设置
'hidden' => false,
'hidedlg' => false,
#显示的渲染设置
'formatter' => "",
'formatoptions' => '',
#编辑配置
'editable' => false,
'edittype' => '',
'editoptions' => '',
#字段是否可排序,默认可排序
'sortbale' => false,
],
//base
[
'label' => '基本',
'name' => 'id',
'index' => 'id',
'formatter' => 'yesno',
],
[
'label' => '时间',
'name' => 'created_at',
'index' => 'created_at',
'formatter' => 'date',
'formatoptions' => "{srcformat:'u',newformat:'Y-m-d H:i:s'}",
],
],
#额外指定key,建议填写
'mk_key' => 'id',
#隐藏渲染的字段
'mk_hidden_column' => [ 'username' ],
#不要渲染的字段
'mk_remove_column' => [ 'id' ],
'mk_top_search' => false,
//表格底部的html代码,注意单双引号的转意
'mk_append' => "Hel\'lo",
//jqgrid内置模块的重写
'mk_extra' => new \yii\web\JsExpression("
//标题,提示,关闭按钮,model参数, 替换掉自带的提示组件。
info_dialog: function (caption, content, c_b, modalopt) {
layer.alert(content, {
icon: 2,
skin: 'layer-ext-moon'
})
},
"),
//扩展按钮
'mk_button_extra' => [
new \yii\web\JsExpression('{
caption: "Adddd",
buttonicon: "ui-icon-add",
onClickButton: function () {
alert("Adding Row");
},
position: "last"
}'),
new \yii\web\JsExpression('{
caption: "delete",
buttonicon: "ui-icon-add",
onClickButton: function () {
alert("Adding Row");
},
position: "last"
}'),
new \yii\web\JsExpression('{
caption: "Hiii",
buttonicon: "ui-icon-add",
onClickButton: function () {
alert("Adding Row");
},
position: "last"
}'),
],
//jqgrid实例化后外面的代码
'mk_js_outside' => new \yii\web\JsExpression("
function ooo(){alert(1)};
"),
//jqgird实例化内部代码,可以是jqgird的配置,也可以是各类事件
'mk_js' => new \yii\web\JsExpression("
cellEdit:true,
"),
//css内容会被压缩后输出
'mk_css' => ".table{background-color:red}",
//字段的渲染响应函数
'mk_formatter' => new \yii\web\JsExpression("
/**可以存放很多函数**/
function yesno(value) {return value+1;}
"),
]);