Yii extension
2018-10-31 本文已影响0人
我是_你的范儿
ActiveForm
- 文件上传
ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]) ?>
select2
- 根据选择顺序排序
maintainOrder = true
- 前端获取选中值
function getSelect2(dom)
{
return $(dom).select2().val();
}
- Ajax 传参
field($model, 'Fdepartment_id')->widget(\kartik\widgets\Select2::classname(), [
'options' => ['placeholder' => '请选择','multiple' => false],
'hideSearch' => true,
'pluginOptions' => [
'ajax'=> [
'url'=>'/index.php?r=router',
'type'=>'GET',
'data' => new JsExpression('function(params) { return {id: id}; }'),
],
'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
'templateResult' => new JsExpression('function(res) { return res.text; }'),
'templateSelection' => new JsExpression('function (res) { return res.text; }'),
]
]);
GridView
- 列表表格直接修改数据提交
use kartik\grid\GridView;
...
GridView::widget([
'export' => false,
"columns"=>[
'attribute' => 'status',
'class'=>'kartik\grid\EditableColumn',
'editableOptions'=>[
'asPopover' => false,
'buttonsTemplate' => '{submit}',
'inputType'=> \kartik\editable\Editable::INPUT_DROPDOWN_LIST,
'displayValueConfig'=> Class::status(),
'data' => Class::status(),
'formOptions' => [
'action' => '/router/status'
]
],
],
]
])
- 列表表格复选框
use kartik\grid\GridView;
...
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'export' => false,
'options' => [ 'class' => 'grid-view', 'id' => 'grid'],
'columns' => [
[ 'class' => 'yii\grid\CheckboxColumn', 'name' => 'id'],
...
]
])
...
<script>
function getCheckbox()
{
return $("#grid").yiiGridView("getSelectedRows");
}
</script>