It is used to show data columns and allows [[enableSorting|sorting]] and [[filter|filtering]] them. A simple data column definition refers to an attribute in the data model of the GridView's data provider. The name of the attribute is specified by [[attribute]]. By setting [[value]] and [[label]], the header and cell content can be customized. A data column differentiates between the [[getDataCellValue|data cell value]] and the [[renderDataCellContent|data cell content]]. The cell value is an un-formatted value that may be used for calculation, while the actual cell content is a [[format|formatted]] version of that value which may contain HTML markup. For more details and usage information on DataColumn, see the guide article on data widgets.
Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends Column
Example #1
0
 public function init()
 {
     parent::init();
     if (!$this->filter) {
         $this->filter = \yii\helpers\ArrayHelper::map(\skeeks\cms\models\CmsSite::find()->all(), 'code', 'name');
     }
 }
Example #2
0
 public function init()
 {
     parent::init();
     if (!isset($this->headerOptions['width'])) {
         $this->headerOptions['width'] = $this->width;
     }
 }
 /**
  * @inheritdoc
  */
 public function actions()
 {
     return ArrayHelper::merge(parent::actions(), ['index' => ['columns' => [['attribute' => 'status', 'class' => \yii\grid\DataColumn::className(), 'filter' => \skeeks\cms\comments2\models\Comments2Message::$statuses, 'format' => 'raw', 'value' => function (\skeeks\cms\comments2\models\Comments2Message $model) {
         if ($model->status == \skeeks\cms\comments2\models\Comments2Message::STATUS_NEW) {
             $class = "default";
         } else {
             if ($model->status == \skeeks\cms\comments2\models\Comments2Message::STATUS_PROCESSED) {
                 $class = "warning";
             } else {
                 if ($model->status == \skeeks\cms\comments2\models\Comments2Message::STATUS_CANCELED) {
                     $class = "danger";
                 } else {
                     if ($model->status == \skeeks\cms\comments2\models\Comments2Message::STATUS_ALLOWED) {
                         $class = "success";
                     }
                 }
             }
         }
         return '<span class="label label-' . $class . '">' . \yii\helpers\ArrayHelper::getValue(\skeeks\cms\comments2\models\Comments2Message::$statuses, $model->status) . '</span>';
     }], ['class' => \skeeks\cms\grid\CreatedAtColumn::className(), 'label' => 'Добавлен'], ['class' => \skeeks\cms\grid\CreatedByColumn::className()], ['attribute' => 'site_code', 'class' => \yii\grid\DataColumn::className(), 'filter' => \yii\helpers\ArrayHelper::map(\skeeks\cms\models\CmsSite::find()->all(), 'code', 'name'), 'value' => function (\skeeks\cms\comments2\models\Comments2Message $model) {
         return $model->site->name;
     }], ['attribute' => 'element_id', 'relation' => 'element', 'class' => \skeeks\cms\grid\CmsContentElementColumn::className()], ['filter' => \yii\helpers\ArrayHelper::map(\skeeks\cms\models\CmsContent::find()->all(), 'id', 'name'), 'attribute' => 'content_id', 'class' => \yii\grid\DataColumn::className(), 'value' => function (\skeeks\cms\comments2\models\Comments2Message $model) {
         return $model->element->cmsContent->name;
     }]]], "status-allowed-multi" => ['class' => AdminMultiModelEditAction::className(), "name" => \skeeks\cms\comments2\Module::t('app', 'Approve'), "eachCallback" => [$this, 'eachMultiStatusAllowed']], "status-canceled-multi" => ['class' => AdminMultiModelEditAction::className(), "name" => \skeeks\cms\comments2\Module::t('app', 'Reject'), "eachCallback" => [$this, 'eachMultiStatusCanceled']], "status-processed-multi" => ['class' => AdminMultiModelEditAction::className(), "name" => \skeeks\cms\comments2\Module::t('app', 'In progress'), "eachCallback" => [$this, 'eachMultiStatusProcessed']]]);
 }
 public function init()
 {
     parent::init();
     $this->content = function (ModelBase $model, $key, $index, DataColumn $column) {
         return Html::a($model->{$column->attribute}, ['view', 'id' => $model->primaryKey], ['title' => Yii::t('common', 'View')]);
     };
 }
    /**
     * @inheritdoc
     */
    public function actions()
    {
        return ArrayHelper::merge(parent::actions(), ['index' => ["columns" => [['class' => CreatedAtColumn::className()], 'id', ['class' => DataColumn::className(), 'attribute' => 'status_code', 'format' => 'raw', 'filter' => ArrayHelper::map(ShopOrderStatus::find()->all(), 'code', 'name'), 'value' => function (ShopOrder $order) {
            return Html::label($order->status->name, null, ['style' => "background: {$order->status->color}", 'class' => "label"]) . "<br />" . Html::tag("small", \Yii::$app->formatter->asDatetime($order->status_at) . " (" . \Yii::$app->formatter->asRelativeTime($order->status_at) . ")");
        }], ['class' => BooleanColumn::className(), 'attribute' => 'payed', 'format' => 'raw'], ['class' => DataColumn::className(), 'attribute' => "canceled", 'format' => "raw", 'filter' => ['Y' => \Yii::t('app', 'Yes'), 'N' => \Yii::t('app', 'No')], 'value' => function (ShopOrder $shopOrder) {
            return $shopOrder->canceled == "Y" ? \Yii::t('app', 'Yes') : \Yii::t('app', 'No');
        }], ['class' => DataColumn::className(), 'attribute' => "user_id", 'label' => \skeeks\cms\shop\Module::t('app', 'Buyer'), 'format' => "raw", 'value' => function (ShopOrder $shopOrder) {
            return (new \skeeks\cms\shop\widgets\AdminBuyerUserWidget(['user' => $shopOrder->user]))->run();
        }], ['class' => DataColumn::className(), 'filter' => false, 'format' => 'raw', 'label' => \skeeks\cms\shop\Module::t('app', 'Good'), 'value' => function (ShopOrder $model) {
            if ($model->shopBaskets) {
                $result = [];
                foreach ($model->shopBaskets as $shopBasket) {
                    $money = \Yii::$app->money->intlFormatter()->format($shopBasket->money);
                    $result[] = Html::a($shopBasket->name, $shopBasket->product->cmsContentElement->url, ['target' => '_blank']) . <<<HTML
  — {$shopBasket->quantity} {$shopBasket->measure_name}
HTML;
                }
                return implode('<hr style="margin: 0px;"/>', $result);
            }
        }], ['class' => DataColumn::className(), 'format' => 'raw', 'attribute' => 'price', 'label' => \skeeks\cms\shop\Module::t('app', 'Sum'), 'value' => function (ShopOrder $model) {
            return \Yii::$app->money->intlFormatter()->format($model->money);
        }], ['class' => DataColumn::className(), 'filter' => ArrayHelper::map(CmsSite::find()->active()->all(), 'id', 'name'), 'attribute' => 'site_id', 'format' => 'raw', 'visible' => false, 'label' => \skeeks\cms\shop\Module::t('app', 'Site'), 'value' => function (ShopOrder $model) {
            return $model->site->name . " [{$model->site->code}]";
        }]]], "view" => ['class' => AdminOneModelEditAction::className(), "name" => \Yii::t('app', "Информация"), "icon" => "glyphicon glyphicon-eye-open", "priority" => 5, "callback" => [$this, 'view']]]);
    }
Example #6
0
 /**
  * @see \yii\grid\GridView::createDataColumn()
  * @inheritdoc
  */
 protected function createDataColumn($text)
 {
     if (!preg_match('/^([^:]+)(:(\\w*))?(:(.*))?$/', $text, $matches)) {
         throw new InvalidConfigException('The column must be specified in the format of "attribute", "attribute:format" or "attribute:format:label"');
     }
     return Yii::createObject(['class' => $this->dataColumnClass ?: DataColumn::className(), 'grid' => $this, 'attribute' => $matches[1], 'format' => isset($matches[3]) ? $matches[3] : 'text', 'label' => isset($matches[5]) ? $matches[5] : null]);
 }
Example #7
0
 public function init()
 {
     parent::init();
     if (!isset($this->headerOptions['width'])) {
         $this->headerOptions['width'] = $this->width;
     }
     $this->contentOptions = ['style' => 'word-wrap: break-word; word-break: break-all;'];
 }
 protected function renderDataCellContent($model, $key, $index)
 {
     if ($this->editable === true) {
         return Html::tag('a', parent::renderDataCellContent($model, $key, $index), ['class' => 'editable']);
     } else {
         return parent::renderDataCellContent($model, $key, $index);
     }
 }
 /**
  * @inheritdoc
  */
 public function actions()
 {
     return ArrayHelper::merge(parent::actions(), ['index' => ["gridConfig" => ['settingsData' => ['order' => SORT_ASC, 'orderBy' => "priority"]], "columns" => ['name', 'priority', ['class' => DataColumn::className(), 'attribute' => "shopPaySystems", 'filter' => false, 'value' => function (ShopDelivery $model) {
         return implode(", ", ArrayHelper::map($model->shopPaySystems, 'id', 'name'));
     }], ['class' => DataColumn::className(), 'attribute' => "price", 'format' => 'raw', 'filter' => false, 'value' => function (ShopDelivery $model) {
         return \Yii::$app->money->intlFormatter()->format($model->money);
     }], ['class' => BooleanColumn::className(), 'attribute' => "active"]]]]);
 }
 /**
  * @inheritdoc
  */
 public function actions()
 {
     return ArrayHelper::merge(parent::actions(), ['index' => ["columns" => ['value', ['class' => DataColumn::className(), 'value' => function (ShopTaxRate $model) {
         return $model->tax->name . " (" . $model->tax->site->name . ")";
     }, 'attribute' => "tax_id"], ['class' => DataColumn::className(), 'value' => function (ShopTaxRate $model) {
         return $model->personType->name;
     }, 'attribute' => "person_type_id"], ['class' => BooleanColumn::className(), 'attribute' => "is_in_price"], ['class' => BooleanColumn::className(), 'attribute' => "active"], ['attribute' => "priority"]]]]);
 }
Example #11
0
 /**
  * Init
  */
 public function init()
 {
     parent::init();
     $this->setDefaultOptions();
     $this->setCellStyleOptions();
     $this->initOptions();
     $this->grid->view->registerJs($this->sortButtonJs());
 }
Example #12
0
 protected function renderDataCellContent($model, $key, $index)
 {
     if ($this->content === null) {
         return $this->getDataCellValue($model, $key, $index);
     } else {
         return parent::renderDataCellContent($model, $key, $index);
     }
 }
Example #13
0
 public function init()
 {
     parent::init();
     $model = $this->grid->filterModel;
     if ($model) {
         $this->filter = $model->getPossibleStatuses();
     }
 }
 /**
  * @inheritdoc
  */
 protected function renderDataCellContent($model, $key, $index)
 {
     if ($this->content === null) {
         return Html::a('<span class="glyphicon glyphicon-arrow-up"></span>', $this->getUrl('up', $model), ['class' => 'order-link']) . Html::a('<span class="glyphicon glyphicon-arrow-down"></span>', $this->getUrl('down', $model), ['class' => 'order-link']);
     } else {
         return parent::renderDataCellContent($model, $key, $index);
     }
 }
 protected function renderDataCellContent($model, $key, $index)
 {
     $text = parent::renderDataCellContent($model, $key, $index);
     if (in_array($this->format, ['text', 'date', 'datetime'])) {
         return Html::a($text, null, $this->grid->prepareDetailsLink($model->id));
     }
     return $text;
 }
Example #16
0
 /**
  * @inheritdoc
  */
 public function getDataCellValue($model, $key, $index)
 {
     if ($this->value !== null) {
         return parent::getDataCellValue($model, $key, $index);
     } else {
         $class = $this->menuClass;
         return $class::create(['model' => $model])->render(MenuButton::class);
     }
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (!isset($this->ajaxOptions['type'])) {
         $this->ajaxOptions['type'] = 'POST';
     }
     $this->ajaxOptions['data'] = new \yii\web\JsExpression('data');
     $this->grid->view->registerJs("\$('.editableCell').change(function() {\n                data = {};\n                data[\$(this).attr('name')] = \$(this).val();\n                submitAttributes = \$(this).data('submit-attributes').split(',');\n                for (var i in submitAttributes) {\n                    data[submitAttributes[i]] = \$(this).data('attribute'+i);\n                }\n                data['dropDownColumnSubmit'] = true;\n                \$.ajax(" . \yii\helpers\Json::encode($this->ajaxOptions) . ");\n        });");
     return parent::init();
 }
 public function init()
 {
     $this->headerOptions = ['class' => 'text-center', 'style' => 'width: 115px'];
     $this->contentOptions = ['class' => 'text-center'];
     parent::init();
     $this->content = function (ModelBase $model, $key, $index, DataColumn $column) {
         return ControllerBase::getYesNoLabel($model->{$column->attribute});
     };
 }
Example #19
0
 protected function renderDataCellContent($model, $key, $index)
 {
     $content = parent::renderDataCellContent($model, $key, $index);
     if ($content == "1") {
         return "<span class=\"label " . $this->true_label_class . "\">" . Yii::t('app', $this->true_value) . "</span>";
     } else {
         return "<span class=\"label " . $this->false_label_class . "\">" . Yii::t('app', $this->false_value) . "</span>";
     }
 }
 /**
  * @inheritdoc
  */
 protected function renderDataCellContent($model, $key, $index)
 {
     $value = parent::renderDataCellContent($model, $key, $index);
     if ($this->getDataCellValue($model, $key, $index) == true) {
         return "<span class=\"label label-success\">{$value}</span>";
     } else {
         return "<span class=\"label label-default\">{$value}</span>";
     }
 }
Example #21
0
 public function init()
 {
     parent::init();
     if (empty($this->content)) {
         $this->content = function ($model) {
             /** @var \frontend\modules\torrent\models\Torrent $model */
             return Html::a($model->getCategoryTag(), '/search?iht=' . $model->category_id, ['title' => 'Browse ' . $model->getCategoryTag() . ' torrents']);
         };
     }
 }
Example #22
0
 protected function renderDataCellContent($model, $key, $index)
 {
     $content = parent::renderDataCellContent($model, $key, $index);
     $options = $this->grid->options;
     if (array_key_exists('href', $options) && $options['href'] != null) {
         $field = $options['field'];
         $content = Html::tag('a', $content, ['href' => $options['href'] . "?" . $field . "=" . $model->{$field}, 'class' => 'btn-block']);
     }
     return $content;
 }
Example #23
0
 public function init()
 {
     parent::init();
     if (empty($this->content)) {
         $this->content = function ($model) {
             /** @var \frontend\modules\torrent\models\Torrent $model */
             return Yii::$app->formatter->asShortSize($model->size);
         };
     }
 }
Example #24
0
 public function init()
 {
     parent::init();
     if (empty($this->content)) {
         $this->content = function ($model) {
             /** @var \frontend\modules\torrent\models\Torrent $model */
             return Yii::$app->formatter->asRelativeTime($model->created_at);
         };
     }
 }
Example #25
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (!$this->controller) {
         throw new InvalidConfigException("controller - " . \Yii::t('app', "not specified") . ".");
     }
     if (!$this->controller instanceof AdminModelEditorController) {
         throw new InvalidConfigException(\Yii::t('app', "{controller} must be inherited from") . ": " . AdminModelEditorController::className());
     }
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     // Set the filter options based on the info we have
     $this->filter = [$this->successValue => $this->successLabel, $this->dangerValue => $this->dangerLabel];
     $this->filterInputOptions = ['prompt' => $this->promptLabel, 'class' => 'form-control', 'id' => null];
     // Get the view
     $view = $this->grid->getView();
     ActiveCheckColumnAsset::register($view);
     return parent::init();
     // TODO: Change the autogenerated stub
 }
Example #27
0
 protected function renderHeaderCellContent()
 {
     $parentHeader = parent::renderHeaderCellContent();
     $sort = $this->grid->dataProvider->getSort();
     $direction = $sort->getAttributeOrder($this->attribute);
     if ($direction === null) {
         return $parentHeader;
     }
     $class = $direction == SORT_ASC ? 'asc' : 'desc';
     return $parentHeader . Html::tag('span', '', ['class' => [$class]]);
 }
 /**
  * Initializes the widget.
  */
 public function init()
 {
     parent::init();
     $this->_messageCategory = 'rk-rowaction';
     $this->initI18N('@rokorolov/rowaction', $this->_messageCategory);
     if ($this->deleteMessage === null) {
         $this->deleteMessage = Yii::t($this->_messageCategory, 'Are you sure you want to delete this item?');
     }
     Html::addCssClass($this->actionOptions, 'rk-row-actions');
     $this->initDefaultButtons();
     $this->registerScripts();
 }
Example #29
-1
 /**
  * @inheritdoc
  */
 protected function renderFilterCellContent()
 {
     if ($this->format == 'boolean') {
         $this->filter = [\Yii::t('app', 'No'), \Yii::t('app', 'Yes')];
     }
     if (is_string($this->filter)) {
         return $this->filter;
     }
     $model = $this->grid->filterModel;
     if ($this->filter !== false && $model instanceof Model && $this->attribute !== null && $model->isAttributeActive($this->attribute)) {
         if ($model->hasErrors($this->attribute)) {
             Html::addCssClass($this->filterOptions, 'has-error');
             $error = ' ' . Html::error($model, $this->attribute, $this->grid->filterErrorOptions);
         } else {
             $error = '';
         }
         if (is_array($this->filter)) {
             $options = array_merge(['prompt' => ''], $this->filterInputOptions);
             return Html::activeDropDownList($model, $this->attribute, $this->filter, $options) . $error;
         } else {
             return Html::activeTextInput($model, $this->attribute, $this->filterInputOptions) . $error;
         }
     } else {
         return parent::renderFilterCellContent();
     }
 }
Example #30
-1
 protected function renderFilterCellContent()
 {
     if (is_string($this->filter)) {
         return $this->filter;
     }
     $model = $this->grid->filterModel;
     if ($this->filter !== false && $model instanceof Model && $this->attribute !== null && $model->isAttributeActive($this->attribute)) {
         if ($model->hasErrors($this->attribute)) {
             $error = Html::error($model, $this->attribute, $this->grid->filterErrorOptions);
         } else {
             $error = '';
         }
         if (is_array($this->filter)) {
             $options = array_merge(['prompt' => ''], $this->filterDropdownOptions);
             if ($model->hasErrors($this->attribute)) {
                 Html::addCssClass($options, 'error');
             }
             return Select::widget(['model' => $model, 'attribute' => $this->attribute, 'items' => $this->filter, 'options' => $options, 'search' => true]) . ' ' . $error;
         } else {
             $options = ['class' => 'fluid'];
             if ($model->hasErrors($this->attribute)) {
                 Html::addCssClass($options, 'error');
             }
             return Elements::input(Html::activeTextInput($model, $this->attribute, $this->filterInputOptions) . $error, $options);
         }
     } else {
         return parent::renderFilterCellContent();
     }
 }