美文网首页
Yii extension

Yii extension

作者: 我是_你的范儿 | 来源:发表于2018-10-31 11:13 被阅读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>

相关文章

网友评论

      本文标题:Yii extension

      本文链接:https://www.haomeiwen.com/subject/yznotqtx.html