To add an EditableColumn to the gridview, add it to the [[GridView::columns|columns]] configuration as follows: php 'columns' => [ ... [ 'class' => EditableColumn::className(), you may configure additional properties here ], ]
Since: 1.0
Author: Kartik Visweswaran (kartikv2@gmail.com)
Inheritance: extends DataColumn
 public static function editable(ActiveRecord $model, $attribute, $editable_type = Editable::INPUT_TEXT, $options = [])
 {
     /* @var Module $module */
     $module = \Yii::$app->getModule('ycm-utils');
     // Init config
     $config = ['attribute' => $attribute, 'class' => EditableColumn::className(), 'editableOptions' => ['inputType' => $editable_type, 'ajaxSettings' => ['url' => Url::to(['/ycm/model/editable', 'name' => $module->ycm->getModelName($model)])]]];
     // Add inner widget config if available
     if (isset(self::$widgetEditableTypeMap[$editable_type])) {
         $typeMethod = self::$widgetEditableTypeMap[$editable_type];
         $config['editableOptions']['options'] = self::$typeMethod($model, $attribute);
     }
     // Add relation config if available
     if ($model->getRelation($attribute, false)) {
         $config = ArrayHelper::merge($config, self::relation($model, $attribute), self::editableRelationConfig($model, $attribute));
     }
     // Check from db selectable type
     if ($choices = ModelHelper::getBooleanChoices($model, $attribute)) {
         $config = ArrayHelper::merge($config, ['editableOptions' => ['options' => ['data' => $choices], 'displayValueConfig' => $choices]], self::selectWidgetFilterConfig($choices));
     } elseif ($choices = ModelHelper::getEnumChoices($model, $attribute)) {
         $config = ArrayHelper::merge($config, ['editableOptions' => ['inputType' => Editable::INPUT_SELECT2, 'options' => ['data' => $choices], 'displayValueConfig' => $choices]], self::selectWidgetFilterConfig($choices));
     }
     return ArrayHelper::merge($config, $options);
 }
Exemple #2
0
 * @var \app\models\Form $searchModel
 */
use kartik\dynagrid\DynaGrid;
use kartik\helpers\Html;
$this->title = Yii::t('app', 'Currencies');
$this->params['breadcrumbs'][] = $this->title;
?>

<?php 
echo app\widgets\Alert::widget(['id' => 'alert']);
$this->beginBlock('add-button');
echo \yii\helpers\Html::a(\kartik\icons\Icon::show('plus') . ' ' . Yii::t('app', 'Add'), ['edit', 'returnUrl' => \app\backend\components\Helper::getReturnUrl()], ['class' => 'btn btn-success']);
echo \app\backend\widgets\RemoveAllButton::widget(['url' => 'remove-all', 'gridSelector' => '.grid-view', 'htmlOptions' => ['class' => 'btn btn-danger pull-right']]);
$this->endBlock();
?>



<div class="row">
    <div class="col-md-12">
        <?php 
echo DynaGrid::widget(['options' => ['id' => 'currencies-grid'], 'columns' => [['class' => \app\backend\columns\CheckboxColumn::className()], 'id', 'name', 'iso_code', 'convert_nominal', 'convert_rate', ['attribute' => 'currency_rate_provider_id', 'class' => \kartik\grid\EditableColumn::className(), 'editableOptions' => ['data' => [0 => '-'] + \app\components\Helper::getModelMap(\app\modules\shop\models\CurrencyRateProvider::className(), 'id', 'name'), 'inputType' => 'dropDownList', 'placement' => 'left', 'formOptions' => ['action' => 'update-editable']], 'filter' => \app\components\Helper::getModelMap(\app\modules\shop\models\CurrencyRateProvider::className(), 'id', 'name'), 'format' => 'raw', 'value' => function ($model, $key, $index, $column) {
    if ($model === null || $model->rateProvider === null) {
        return null;
    }
    return Html::tag('div', $model->rateProvider->name, ['class' => $model->rateProvider->name]);
}], ['class' => \app\backend\components\ActionColumn::className()]], 'theme' => 'panel-default', 'gridOptions' => ['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'hover' => true, 'panel' => ['heading' => $this->render('_tabs', ['currencies' => true]), 'after' => $this->blocks['add-button']]]]);
?>
    </div>
</div>
Exemple #3
0
<div class="row">
    <div class="col-md-4">
        <?php 
echo TreeWidget::widget(['treeDataRoute' => ['getTree'], 'doubleClickAction' => ContextMenuHelper::actionUrl(['index', 'returnUrl' => Helper::getReturnUrl()], ['parent_id' => 'id']), 'contextMenuItems' => ['show' => ['label' => 'Show products in category', 'icon' => 'fa fa-folder-open', 'action' => ContextMenuHelper::actionUrl(['index'], ['parent_id' => 'id'])], 'createProduct' => ['label' => 'Create product in this category', 'icon' => 'fa fa-plus-circle', 'action' => ContextMenuHelper::actionUrl(['edit', 'returnUrl' => Helper::getReturnUrl()], ['parent_id' => 'id'])], 'edit' => ['label' => 'Edit category', 'icon' => 'fa fa-pencil', 'action' => ContextMenuHelper::actionUrl(['/shop/backend-category/edit', 'returnUrl' => Helper::getReturnUrl()])], 'create' => ['label' => 'Create category', 'icon' => 'fa fa-plus-circle', 'action' => ContextMenuHelper::actionUrl(['/shop/backend-category/edit', 'returnUrl' => Helper::getReturnUrl()], ['parent_id' => 'id'])], 'delete' => ['label' => 'Delete', 'icon' => 'fa fa-trash-o', 'action' => new \yii\web\JsExpression("function(node) {\n                            jQuery('#delete-category-confirmation')\n                                .attr('data-url', '/backend/category/delete?id=' + jQuery(node.reference[0]).data('id'))\n                                .attr('data-items', '')\n                                .modal('show');\n                            return true;\n                        }")]]]);
?>
    </div>
    <div class="col-md-8" id="jstree-more">
        <?php 
echo DynaGrid::widget(['options' => ['id' => 'Product-grid'], 'columns' => [['class' => \kartik\grid\CheckboxColumn::className(), 'options' => ['width' => '10px']], ['class' => 'yii\\grid\\DataColumn', 'attribute' => 'id'], ['class' => 'yii\\grid\\DataColumn', 'attribute' => 'name'], 'slug', ['class' => \kartik\grid\EditableColumn::className(), 'attribute' => 'active', 'editableOptions' => ['data' => [0 => Yii::t('app', 'Inactive'), 1 => Yii::t('app', 'Active')], 'inputType' => 'dropDownList', 'placement' => 'left', 'formOptions' => ['action' => 'update-editable']], 'filter' => [0 => Yii::t('app', 'Inactive'), 1 => Yii::t('app', 'Active')], 'format' => 'raw', 'value' => function (Product $model) {
    if ($model === null || $model->active === null) {
        return null;
    }
    if ($model->active === 1) {
        $label_class = 'label-success';
        $value = 'Active';
    } else {
        $value = 'Inactive';
        $label_class = 'label-default';
    }
    return \yii\helpers\Html::tag('span', Yii::t('app', $value), ['class' => "label {$label_class}"]);
}], ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'price', 'editableOptions' => ['inputType' => \kartik\editable\Editable::INPUT_TEXT, 'formOptions' => ['action' => 'update-editable']]], ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'old_price', 'editableOptions' => ['inputType' => \kartik\editable\Editable::INPUT_TEXT, 'formOptions' => ['action' => 'update-editable']]], ['attribute' => 'currency_id', 'class' => \kartik\grid\EditableColumn::className(), 'editableOptions' => ['data' => [0 => '-'] + \app\components\Helper::getModelMap(\app\modules\shop\models\Currency::className(), 'id', 'name'), 'inputType' => 'dropDownList', 'placement' => 'left', 'formOptions' => ['action' => 'update-editable']], 'filter' => \app\components\Helper::getModelMap(\app\modules\shop\models\Currency::className(), 'id', 'name'), 'format' => 'raw', 'value' => function ($model) {
    if ($model === null || $model->currency === null || $model->currency_id === 0) {
        return null;
    }
    return \yii\helpers\Html::tag('div', $model->currency->name, ['class' => $model->currency->name]);
}], ['class' => 'kartik\\grid\\EditableColumn', 'attribute' => 'sku', 'editableOptions' => ['inputType' => \kartik\editable\Editable::INPUT_TEXT, 'formOptions' => ['action' => 'update-editable'], 'placement' => 'left']], 'date_modified', ['class' => 'app\\backend\\components\\ActionColumn', 'buttons' => [['url' => '@product', 'icon' => 'eye', 'class' => 'btn-info', 'label' => Yii::t('app', 'Preview'), 'appendReturnUrl' => false, 'url_append' => '', 'attrs' => ['model', 'mainCategory.category_group_id'], 'keyParam' => null], ['url' => 'edit', 'icon' => 'pencil', 'class' => 'btn-primary', 'label' => Yii::t('app', 'Edit')], ['url' => 'clone', 'icon' => 'copy', 'class' => 'btn-success', 'label' => Yii::t('app', 'Clone')], ['url' => 'delete', 'icon' => 'trash-o', 'class' => 'btn-danger', 'label' => Yii::t('app', 'Delete'), 'options' => ['data-action' => 'delete']]]]], 'theme' => 'panel-default', 'gridOptions' => ['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'hover' => true, 'panel' => ['heading' => '<h3 class="panel-title">' . $this->title . '</h3>', 'after' => $this->blocks['add-button']]]]);
?>
    </div>
</div>
Exemple #4
0
        <?php 
BackendWidget::begin(['icon' => 'tag', 'title' => Yii::t('app', 'Additional parameters'), 'footer' => $this->blocks['submit']]);
if ($model->handler() !== null) {
    echo $this->render($model->handler()->slider_edit_view_file, ['model' => $model, 'form' => $form, 'abstractModel' => $abstractModel]);
} else {
    echo Yii::t('app', 'Save slider to configure additional params of slider implementation.');
}
BackendWidget::end();
?>
    </div>
</div>
<div class="row">
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">

        <?php 
echo \kartik\dynagrid\DynaGrid::widget(['options' => ['id' => 'slides-grid'], 'columns' => [['class' => 'yii\\grid\\DataColumn', 'attribute' => 'id'], ['attribute' => 'sort_order', 'class' => \kartik\grid\EditableColumn::className(), 'editableOptions' => ['inputType' => Editable::INPUT_TEXT, 'formOptions' => $editable_formOptions, 'placement' => PopoverX::ALIGN_BOTTOM]], ['attribute' => 'image', 'class' => '\\app\\components\\ImageColumn'], ['attribute' => 'link', 'class' => \kartik\grid\EditableColumn::className(), 'editableOptions' => ['inputType' => Editable::INPUT_TEXT, 'formOptions' => $editable_formOptions, 'placement' => PopoverX::ALIGN_BOTTOM]], ['attribute' => 'custom_view_file', 'class' => \kartik\grid\EditableColumn::className(), 'editableOptions' => ['inputType' => Editable::INPUT_TEXT, 'formOptions' => $editable_formOptions, 'placement' => PopoverX::ALIGN_BOTTOM]], ['attribute' => 'css_class', 'class' => \kartik\grid\EditableColumn::className(), 'editableOptions' => ['inputType' => Editable::INPUT_TEXT, 'formOptions' => $editable_formOptions, 'placement' => PopoverX::ALIGN_BOTTOM]], ['attribute' => 'active', 'class' => \kartik\grid\EditableColumn::className(), 'editableOptions' => ['inputType' => Editable::INPUT_CHECKBOX, 'formOptions' => $editable_formOptions, 'placement' => PopoverX::ALIGN_BOTTOM], 'format' => 'raw', 'value' => function ($model, $key, $index, $column) {
    if ($model === null || $model->active === null) {
        return null;
    }
    return $model->active ? Icon::show('check txt-color-green') : Icon::show('times txt-color-red');
}], ['class' => 'app\\backend\\components\\ActionColumn', 'buttons' => [['url' => 'delete-slide', 'icon' => 'trash-o', 'class' => 'btn-danger', 'label' => Yii::t('app', 'Delete')]]]], 'theme' => 'panel-default', 'gridOptions' => ['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'hover' => true, 'panel' => ['heading' => '<h3 class="panel-title">' . Yii::t('app', 'Slides') . '</h3>', 'after' => Html::a(Icon::show('plus') . ' ' . Yii::t('app', 'Add slide'), ['new-slide', 'slider_id' => $model->id], ['class' => 'btn btn-primary'])]]]);
?>

    </div>
</div>
<?php 
ActiveForm::end();
?>
<section style="display: none" type="x-tmpl-underscore" id="image-upload-template">
    <?php 
ActiveForm::begin(['action' => 'upload-slide', 'options' => ['enctype' => 'multipart/form-data', 'type' => 'post']]);
Exemple #5
0
<div class="reviews-index">
    <?php 
echo DynaGrid::widget(['options' => ['id' => 'reviews-grid'], 'theme' => 'panel-default', 'gridOptions' => ['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'hover' => true, 'panel' => ['heading' => Html::tag('h3', $this->title, ['class' => 'panel-title']), 'after' => $this->blocks['add-button']]], 'columns' => [['class' => \kartik\grid\CheckboxColumn::className(), 'options' => ['width' => '10px']], 'id', 'author_email', ['attribute' => 'submission.form.name', 'label' => Yii::t('app', 'Form name')], ['attribute' => 'object_id', 'filter' => \app\components\Helper::getModelMap(\app\models\Object::className(), 'id', 'name'), 'label' => Yii::t('app', 'Object'), 'value' => function ($data) {
    $obj = \app\models\Object::findById($data->object_id);
    return is_null($obj) ? Yii::t('yii', '(not set)') : $obj->name;
}], ['class' => yii\grid\DataColumn::className(), 'attribute' => 'object_model_id', 'value' => function ($data) {
    /** @var $object \app\models\Object*/
    if (null !== ($object = \app\models\Object::findById($data->object_id))) {
        $class = $object->object_class;
        $resource = $class::findById($data->object_model_id);
        if (null !== $resource) {
            return $resource->name;
        }
        return null;
    }
}], ['class' => yii\grid\DataColumn::className(), 'attribute' => 'processed_by_user_id', 'value' => function ($data) {
    if (isset($data->submission)) {
        if (null !== $data->submission->processed_by_user_id) {
            /** @var $user \app\modules\user\models\User */
            $user = \app\modules\user\models\User::findIdentity($data->submission->processed_by_user_id);
            return $user->getDisplayName();
        } else {
            return Yii::t('app', 'Guest');
        }
    }
    return null;
}], 'submission.date_received', ['attribute' => 'status', 'class' => \kartik\grid\EditableColumn::className(), 'editableOptions' => ['inputType' => \kartik\editable\Editable::INPUT_DROPDOWN_LIST, 'placement' => \kartik\popover\PopoverX::ALIGN_LEFT, 'data' => Review::getStatuses(), 'formOptions' => ['action' => ['update-status']]], 'filter' => Review::getStatuses(), 'format' => 'raw'], ['class' => 'app\\backend\\components\\ActionColumn', 'buttons' => function ($model, $key, $index, $parent) {
    return [['url' => 'view', 'icon' => 'eye', 'class' => 'btn-info', 'label' => Yii::t('app', 'View')], ['url' => 'delete', 'icon' => 'trash-o', 'class' => 'btn-danger', 'label' => 'Delete', 'options' => ['data-action' => 'delete']]];
}]]]);
?>
</div>
Exemple #6
0
 /**
  * @param ActiveRecord $model
  * @param $options
  * @return array
  */
 public function createListWidget($model, $options)
 {
     if (is_array($options) && isset($options[0]) && isset($options[1])) {
         $attribute = array_shift($options);
         $type = array_shift($options);
         $editable = isset($options['editable']) && $options['editable'] == true;
         $editableType = isset($options['editableType']) ? $options['editableType'] : Editable::INPUT_TEXT;
         unset($options['editable'], $options['editableType']);
         $config = ['attribute' => $attribute];
         $choices = [];
         switch ($type) {
             case 'date':
                 $config = ['attribute' => $attribute, 'format' => ['datetime', 'php:Y-m-d'], 'options' => ['style' => 'width:240px'], 'filterWidgetOptions' => ['type' => DatePicker::TYPE_RANGE, 'attribute2' => $attribute . '_to'], 'filterType' => DatePicker::className()];
                 break;
             case 'datetime':
                 $config = ['attribute' => $attribute, 'format' => ['datetime', 'php:Y-m-d H:i:s'], 'options' => ['style' => 'width:240px'], 'filterWidgetOptions' => ['type' => DatePicker::TYPE_RANGE, 'attribute2' => $attribute . '_to'], 'filterType' => DatePicker::className()];
                 break;
             case 'boolean':
                 $choices = ModelHelper::getBooleanChoices($model, $attribute);
                 $config = ['class' => \kartik\grid\BooleanColumn::className(), 'attribute' => $attribute, 'filterWidgetOptions' => ['data' => $choices, 'pluginOptions' => ['allowClear' => true, 'placeholder' => 'Select...']], 'filterType' => Select2::className()];
                 break;
             case 'enumerate':
                 $choices = ModelHelper::getEnumChoices($model, $attribute);
                 $config = ['attribute' => $attribute, 'filterWidgetOptions' => ['data' => $choices, 'pluginOptions' => ['allowClear' => true, 'placeholder' => 'Select...']], 'filterType' => Select2::className()];
                 break;
             case 'relation':
                 $relation = ModelHelper::getRelation($model, $attribute);
                 $choices = ModelHelper::getSelectChoices(new $relation->modelClass());
                 $config = ['label' => ucfirst(strpos($attribute, '.') !== false ? substr($attribute, strrpos($attribute, '.') + 1) : $attribute), 'attribute' => $attribute, 'value' => function ($model, $key, $index, $widget) use($attribute) {
                     return $model ? ModelHelper::getLabelRelationValue($model, $attribute) : null;
                 }, 'filter' => !$relation->multiple ? $choices : false, 'filterWidgetOptions' => ['data' => $choices, 'pluginOptions' => ['allowClear' => true, 'placeholder' => '...']], 'filterType' => Select2::className()];
                 break;
         }
         if ($editable) {
             switch ($type) {
                 case 'date':
                     $config['editableOptions'] = ['inputType' => Editable::INPUT_DATE];
                     break;
                 case 'datetime':
                     $config['editableOptions'] = ['inputType' => Editable::INPUT_DATETIME];
                     break;
                 case 'boolean':
                 case 'enumerate':
                     $config['editableOptions'] = ['inputType' => Editable::INPUT_SELECT2, 'options' => ['data' => $choices], 'displayValueConfig' => $choices];
                     break;
                 case 'relation':
                     $relation = ModelHelper::getRelation($model, $attribute);
                     $config['editableOptions'] = ['inputType' => Editable::INPUT_SELECT2, 'size' => 'lg', 'options' => ['options' => ['multiple' => $relation->multiple], 'data' => $choices, 'pluginOptions' => count($choices) > 20 ? ['minimumInputLength' => 3, 'ajax' => ['url' => Url::to(['/ycm/model/choices', 'name' => $this->getModelName(new $relation->modelClass())]), 'dataType' => 'json', 'processResults' => new JsExpression('function (results) { return results; }')]] : null], 'displayValueConfig' => !$relation->multiple ? $choices : null];
                     break;
                 default:
                     $config['editableOptions']['options'] = $config;
                     break;
             }
             $config = ArrayHelper::merge(['editableOptions' => ['inputType' => $editableType]], $config, ['class' => EditableColumn::className(), 'editableOptions' => ['ajaxSettings' => ['url' => Url::to(['/ycm/model/editable', 'name' => $this->getModelName($model)])]]]);
         }
         $options = ArrayHelper::merge($config, $options);
     }
     return $options;
 }