To add a SerialColumn to the GridView, add it to the [[GridView::columns|columns]] configuration as follows:
php
'columns' => [
...
[
'class' => 'yii\grid\SerialColumn',
you may configure additional properties here
],
]
For more details and usage information on SerialColumn, see the guide article on data widgets.
public static function CreateGridWithDropDownListHeader($dataProvider, $form, $header_model, $arr_header_values) { $columns_config = [['class' => SerialColumn::className()]]; $i = 0; foreach ($header_model as $key => $value) { $columns_config[] = ['header' => $form->field($header_model, $key, ['inputOptions' => ['label' => '']])->dropDownList($arr_header_values), 'attribute' => $i]; $i++; } $dynamic_grid_view = GridView::widget(['dataProvider' => $dataProvider, 'columns' => $columns_config]); return $dynamic_grid_view; }
/** * @inheritdoc */ public function actions() { return ArrayHelper::merge(parent::actions(), ['index' => ["gridConfig" => [], "columns" => [['class' => \yii\grid\SerialColumn::className()], ['class' => \yii\grid\DataColumn::className(), 'attribute' => 'name', 'format' => 'raw', 'value' => function (\skeeks\cms\shop\models\ShopBasket $shopBasket) { $widget = new \skeeks\cms\modules\admin\widgets\AdminImagePreviewWidget(['image' => $shopBasket->product->cmsContentElement->image]); return $widget->run(); }], ['class' => \yii\grid\DataColumn::className(), 'attribute' => 'name', 'format' => 'raw', 'value' => function (\skeeks\cms\shop\models\ShopBasket $shopBasket) { if ($shopBasket->product) { return Html::a($shopBasket->name, $shopBasket->product->cmsContentElement->url, ['target' => '_blank', 'titla' => \Yii::t('skeeks/shop/app', 'Watch Online'), 'data-pjax' => 0]); } else { return $shopBasket->name; } }], ['class' => \yii\grid\DataColumn::className(), 'attribute' => 'quantity', 'value' => function (\skeeks\cms\shop\models\ShopBasket $shopBasket) { return $shopBasket->quantity . " " . $shopBasket->measure_name; }], ['class' => \yii\grid\DataColumn::className(), 'label' => \Yii::t('skeeks/shop/app', 'Price'), 'attribute' => 'price', 'format' => 'raw', 'value' => function (\skeeks\cms\shop\models\ShopBasket $shopBasket) { if ($shopBasket->discount_value) { return "<span style='text-decoration: line-through;'>" . \Yii::$app->money->intlFormatter()->format($shopBasket->moneyOriginal) . "</span><br />" . Html::tag('small', $shopBasket->notes) . "<br />" . \Yii::$app->money->intlFormatter()->format($shopBasket->money) . "<br />" . Html::tag('small', \Yii::t('skeeks/shop/app', 'Discount') . ": " . $shopBasket->discount_value); } else { return \Yii::$app->money->intlFormatter()->format($shopBasket->money) . "<br />" . Html::tag('small', $shopBasket->notes); } }], ['class' => \yii\grid\DataColumn::className(), 'label' => \Yii::t('skeeks/shop/app', 'Sum'), 'attribute' => 'price', 'format' => 'raw', 'value' => function (\skeeks\cms\shop\models\ShopBasket $shopBasket) { return \Yii::$app->money->intlFormatter()->format($shopBasket->money->multiply($shopBasket->quantity)); }]]]]); }
<?php use yii\helpers\Html; use yii\grid\GridView; use app\modules\tasks\widgets\TasksListWidget; use yii\grid\SerialColumn; /* @var $this yii\web\View */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Результаты'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="panel panel-body"> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'layout' => "{items}", 'columns' => [['class' => SerialColumn::className()], ['attribute' => 'login', 'label' => 'Участник'], ['attribute' => 'result', 'format' => 'raw', 'value' => function ($data) { return isset($data->result) ? $data->result : 0; }]]]); ?> <?php if (!isset($_GET['blank'])) { ?> <a href="/scoreboard?blank=show" target="_blank">Версия для мониторов</a> <?php } ?> </div>
/** * @var \yii\web\View $this * @var \opus\ecom\Basket $basket * @var \app\models\ar\User[] $users */ use yii\helpers\Html; use opus\ecom\Basket; ?> <h1>Your shopping basket</h1> <div class="row"> <div class="col-lg-8 "> <?php echo \opus\ecom\widgets\BasketGridView::widget(['basket' => $basket, 'columns' => [['class' => \yii\grid\SerialColumn::className()], 'label', 'price:price', 'vat:percent', 'basketQuantity', 'totalPrice:price', ['class' => \yii\grid\ActionColumn::className(), 'template' => '{delete}']]]); echo \opus\ecom\widgets\BasketGridView::widget(['basket' => $basket, 'itemType' => Basket::ITEM_DISCOUNT, 'layout' => '{items}', 'columns' => ['label:text:Discounts']]); echo Html::a('Empty basket', ['basket/clear'], ['class' => 'btn btn-danger']); ?> </div> </div> <div class="col-lg-4 row"> <?php $totalPrice = $basket->getAttributeTotal('totalPrice', Basket::ITEM_PRODUCT); $vat = $basket->getAttributeTotal('totalVat', Basket::ITEM_PRODUCT); $priceWithoutVat = $totalPrice - $vat; ?> <h4> Total: <?php
use ext\Helper; use yii\rbac\Item; use yii\grid\SerialColumn; $this->title = Yii::t('app', '报价清单'); $this->params['breadcrumbs'][] = ['label' => $this->title, 'url' => ['index']]; $this->params['breadcrumbs'][] = Yii::t('app', '列表'); $id = 'medicine-grid'; ?> <div class="row"> <div class="col-md-12 portlet light"> <?php echo GridView::widget(['id' => $id, 'title' => Yii::t('app', 'Medicine'), 'moreActionsTemplate' => '{export}', 'actionsTemplate' => '{Create}{Delete}', 'actions' => ['Create' => function () { return Html::tag('a', '添加清单', ['class' => 'btn btn-primary', 'href' => Url::toRoute('create'), 'data-action' => 'get.modal']); }, 'Delete' => function () { return Html::tag('a', '删除清单', ['class' => 'btn btn-default', 'href' => Url::toRoute('multi-delete'), 'data-action' => 'confirm.multi.grid-view.modal', 'data-message' => '确认删除 <b>${num}</b> 记录? 删除后不可恢复!']); }], 'dataProvider' => $dataProvider, 'filterModel' => $filterModel, 'columns' => [['class' => SerialColumn::className()], ['class' => CheckboxColumn::className()], ['attribute' => 'id', 'label' => '编号'], ['attribute' => 'name', 'label' => '品名'], ['attribute' => 'sid', 'label' => '类名', 'content' => function ($model, $key, $index) { return $model['serviceCategory']['name']; }], ['attribute' => 'fid', 'label' => '规格', 'content' => function ($model, $key, $index) { return $model['specifications']['name']; }], ['attribute' => 'cid', 'label' => '城市', 'content' => function ($model, $key, $index) { return $model['city']['name']; }], ['attribute' => 'sexual_taste', 'label' => '性味'], ['attribute' => 'price', 'label' => '价格'], ['attribute' => 'amount', 'label' => '数量'], ['attribute' => 'create_time', 'label' => '创建时间', 'format' => 'datetime'], ['attribute' => 'status', 'label' => '状态', 'filter' => Dict::$medicineStatus, 'content' => function ($model, $key, $index, $column) { if ($model['status'] == Dict::MEDICINE_STATUS_PENDING) { return '<span class="label label-sm label-danger">' . Dict::$medicineStatus[Dict::MEDICINE_STATUS_PENDING] . '</span>'; } else { if ($model['status'] == Dict::MEDICINE_STATUS_COMPLETE) { return '<span class="label label-sm label-success">' . Dict::$medicineStatus[Dict::MEDICINE_STATUS_COMPLETE] . '</span>'; } else { return '<span class="label label-sm label-default">' . Dict::$medicineStatus[Dict::MEDICINE_STATUS_CANCEL] . '</span>'; } }
use app\modules\admin\components\grid\LinkColumn; use app\modules\admin\components\grid\SetColumn; use app\modules\main\models\Article; use app\modules\admin\components\widgets\AdminBoxWidget; use yii\grid\SerialColumn; /* @var $this yii\web\View */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Module::t('app', 'ADMIN_ARTICLE'); $this->params['breadcrumbs'][] = ['label' => Module::t('app', 'ADMIN'), 'url' => ['default/index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="admin-article-index"> <?php AdminBoxWidget::begin(['type' => AdminBoxWidget::TYPE_INFO, 'title' => Html::a('<i class="fa fa-plus-circle"></i>' . ' ' . Module::t('app', 'ADMIN_ARTICLE_ADD'), ['create'], ['class' => 'btn btn-success btn-xs'])]); ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'summary' => false, 'columns' => [['class' => SerialColumn::className()], ['class' => LinkColumn::className(), 'attribute' => 'title'], ['attribute' => 'category_id', 'value' => function ($data) { return $data->category->title; }], ['attribute' => 'author_id', 'value' => function ($data) { return $data->author->username; }], ['class' => SetColumn::className(), 'attribute' => 'status', 'name' => 'ArticleStatusName', 'cssCLasses' => [Article::ARTICLE_ACTIVE => 'success', Article::ARTICLE_INACTIVE => 'warning']], ['attribute' => 'created_at', 'format' => 'datetime']]]); ?> <?php AdminBoxWidget::end(); ?> </div>
?> <?php echo \skeeks\cms\modules\admin\widgets\BlockTitleWidget::widget(['content' => 'Комментарий']); ?> <?php echo \yii\widgets\DetailView::widget(['model' => $model, 'template' => "<tr><th style='width: 50%; text-align: right;'>{label}</th><td>{value}</td></tr>", 'attributes' => [['label' => \skeeks\cms\shop\Module::t('app', 'Comment'), 'format' => 'raw', 'value' => $form->field($model, 'comments')->textarea(['rows' => 5])->hint(\skeeks\cms\shop\Module::t('app', 'Internal comment, the customer (buyer) does not see'))->label(false)]]]); ?> <?php echo \skeeks\cms\modules\admin\widgets\BlockTitleWidget::widget(['content' => \skeeks\cms\shop\Module::t('app', 'The composition of the order')]); ?> <?php echo \skeeks\cms\modules\admin\widgets\GridView::widget(['dataProvider' => new \yii\data\ArrayDataProvider(['models' => $model->shopBaskets]), 'layout' => "{items}\n{pager}", 'columns' => [['class' => \yii\grid\SerialColumn::className()], ['class' => \yii\grid\DataColumn::className(), 'attribute' => 'name', 'format' => 'raw', 'value' => function (\skeeks\cms\shop\models\ShopBasket $shopBasket) { $widget = new \skeeks\cms\modules\admin\widgets\AdminImagePreviewWidget(['image' => $shopBasket->product->cmsContentElement->image]); return $widget->run(); }], ['class' => \yii\grid\DataColumn::className(), 'attribute' => 'name', 'format' => 'raw', 'value' => function (\skeeks\cms\shop\models\ShopBasket $shopBasket) { if ($shopBasket->product) { return Html::a($shopBasket->name, $shopBasket->product->cmsContentElement->url, ['target' => '_blank', 'titla' => "Смотреть на сайте", 'data-pjax' => 0]); } else { return $shopBasket->name; } }], ['class' => \yii\grid\DataColumn::className(), 'attribute' => 'quantity', 'value' => function (\skeeks\cms\shop\models\ShopBasket $shopBasket) { return $shopBasket->quantity . " " . $shopBasket->measure_name; }], ['class' => \yii\grid\DataColumn::className(), 'label' => \skeeks\cms\shop\Module::t('app', 'Price'), 'attribute' => 'price', 'format' => 'raw', 'value' => function (\skeeks\cms\shop\models\ShopBasket $shopBasket) { if ($shopBasket->discount_value) { return "<span style='text-decoration: line-through;'>" . \Yii::$app->money->intlFormatter()->format($shopBasket->moneyOriginal) . "</span><br />" . Html::tag('small', $shopBasket->notes) . "<br />" . \Yii::$app->money->intlFormatter()->format($shopBasket->money) . "<br />" . Html::tag('small', \skeeks\cms\shop\Module::t('app', 'Discount') . ": " . $shopBasket->discount_value); } else { return \Yii::$app->money->intlFormatter()->format($shopBasket->money) . "<br />" . Html::tag('small', $shopBasket->notes);
/** * @inheritdoc */ public function init() { $this->parseFormat(); $this->parseVisibility(); parent::init(); $this->setPageRows(); }
public function getColumns() { return [['class' => SerialColumn::className()], 'employee', 'number', 'limit', ['attribute' => 'expenditure', 'format' => 'decimal'], 'comment']; }
<?php use yii\helpers\Html; $this->title = 'Опросы'; $this->params['breadcrumbs'][] = $this->title; echo \yii\grid\GridView::widget(['summary' => false, 'dataProvider' => $dataProvider, 'columns' => [['class' => \yii\grid\SerialColumn::className()], ['format' => 'html', 'attribute' => 'name', 'value' => function ($model) { return Html::a($model->name, $model->fullLink); }], ['attribute' => 'dateEnd', 'value' => function ($model) { return \Yii::$app->formatter->asRelativeTime($model->dateEnd); }], ['label' => 'Голосов', 'value' => function ($model) { return count($model->votes); }]]]);
<?php use yii\bootstrap\Html; use yii\grid\GridView; use yii\grid\SerialColumn; use yii\helpers\Url; $this->title = 'RSS ленты'; $this->params['breadcrumbs'][] = $this->title; echo GridView::widget(['dataProvider' => $dataProvider, 'summary' => false, 'tableOptions' => ['style' => 'width: 100%'], 'columns' => [['class' => SerialColumn::className()], ['attribute' => 'name'], ['attribute' => 'link', 'format' => 'raw', 'value' => function ($model) { return Html::a('xml', Url::to(['/rss/' . $model->fullLink]), ['class' => 'btn btn-link']); }]]]);
<?php use app\components\Formatter; use app\modules\spisok_slushatelej\Asset; use app\modules\spisok_slushatelej\grid\FioColumn; use yii\data\ActiveDataProvider; use yii\grid\GridView; use yii\grid\SerialColumn; use app\records\Kurs; use app\modules\spisok_slushatelej\grid\ActionColumn; use app\modules\spisok_slushatelej\grid\ContactsColumn; use app\modules\spisok_slushatelej\grid\WorkColumn; use yii\web\View; /** * @var $provider ActiveDataProvider * @var $kursRecord Kurs * @var $this View */ Asset::register($this); ?> <div class="spisokslushatelej-editor"> <?php echo GridView::widget(['caption' => "Слушатели курса «{$kursRecord->nazvanie}»", 'dataProvider' => $provider, 'layout' => "{items}", 'tableOptions' => ['class' => 'table'], 'columns' => [['class' => SerialColumn::className()], ['class' => FioColumn::className(), 'header' => 'Ф. И. О.', 'headerOptions' => ['class' => 'cell-data'], 'contentOptions' => ['class' => 'cell-data']], ['class' => ContactsColumn::className(), 'header' => 'Личные контакты', 'headerOptions' => ['class' => 'cell-data'], 'contentOptions' => ['class' => 'cell-data']], ['class' => WorkColumn::className(), 'header' => 'Работа', 'headerOptions' => ['class' => 'cell-data'], 'contentOptions' => ['class' => 'cell-data']], ['class' => ActionColumn::className(), 'headerOptions' => ['class' => 'cell-action'], 'contentOptions' => ['class' => 'cell-action']]]]); ?> </div>
</div> <?php } ?> </div> <?php if ($tab == 1) { ?> <div id = "list-devices" class="row"> <h3> Список устройств </h3> <?php $deviceProvider = AdminWorkplaces::devicesProvider($model->id); $s = 0; if ($deviceProvider) { echo GridView::widget(['dataProvider' => $deviceProvider, 'columns' => [['class' => \yii\grid\SerialColumn::className()], ['attribute' => 'device_type_title', 'header' => 'Тип', 'value' => function ($device) { if ($device['parent_devices_id']) { return '[' . $device['parent_devices_id'] . '] ' . $device['device_type_title']; } else { return $device['device_type_title']; } }], ['attribute' => 'devices_brand', 'header' => 'Бренд'], ['attribute' => 'devices_model', 'header' => 'Модель'], ['attribute' => 'devices_sn', 'header' => 'SN'], ['attribute' => 'devices_id', 'header' => 'ID'], ['attribute' => 'devices_specification', 'header' => 'Спецификация'], ['attribute' => 'devices_device_note', 'header' => 'Заметка']]]); } ?> </div> <?php } elseif ($tab == 2) { ?> <div> </div> <?php
use ext\grid\CheckboxColumn; use ext\Helper; use yii\grid\SerialColumn; $this->title = Yii::t('app', '热卖商品'); $this->params['breadcrumbs'][] = ['label' => $this->title, 'url' => ['index']]; $this->params['breadcrumbs'][] = Yii::t('app', '列表'); $id = 'hotsale-grid'; ?> <div class="row"> <div class="col-md-12 portlet light"> <?php echo GridView::widget(['id' => $id, 'title' => Yii::t('app', 'Hotsale'), 'moreActionsTemplate' => '{export}', 'actionsTemplate' => '{Create} {Disable} {Delete}', 'actions' => ['Create' => function () { return Html::tag('a', '添加商品', ['class' => 'btn btn-primary', 'href' => Url::toRoute('create'), 'data-action' => 'get.modal']); }, 'Delete' => function () { return Html::tag('a', '删除商品', ['class' => 'btn btn-default', 'href' => Url::toRoute('multi-delete'), 'data-action' => 'confirm.multi.grid-view.modal', 'data-message' => '确认删除<b>${num}</b>记录? 删除后不可恢复!']); }], 'dataProvider' => $dataProvider, 'filterModel' => $filterModel, 'columns' => [['class' => SerialColumn::className()], ['class' => CheckboxColumn::className()], ['attribute' => 'id', 'label' => '编号'], ['attribute' => 'name', 'label' => '品名'], ['attribute' => 'sexual_taste', 'label' => '性味'], ['attribute' => 'price', 'label' => '价格'], ['attribute' => 'create_time', 'label' => '创建时间', 'format' => 'datetime'], ['attribute' => 'status', 'label' => '状态', 'filter' => Dict::$hotsale, 'content' => function ($model, $key, $index, $column) { if ($model['status'] == Dict::HOTSALE_STATUS_PENDING) { return '<span class="label label-sm label-danger">' . Dict::$hotsale[Dict::HOTSALE_STATUS_PENDING] . '</span>'; } else { if ($model['status'] == Dict::HOTSALE_STATUS_COMPLETE) { return '<span class="label label-sm label-success">' . Dict::$hotsale[Dict::HOTSALE_STATUS_COMPLETE] . '</span>'; } else { return '<span class="label label-sm label-default">' . Dict::$hotsale[Dict::HOTSALE_STATUS_CANCEL] . '</span>'; } } }], ['class' => ActionColumn::className(), 'template' => '{view} {update}']]]); ?> </div> </div>
<?php use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $admins \yii\data\ActiveDataProvider */ $this->title = Yii::t('happycode', 'Administrators'); $this->params['breadcrumbs'][] = $this->title; ?> <a href="<?php echo \yii\helpers\Url::to(['admin/add-admin']); ?> " class="btn btn-success pull-right"> <?php echo Yii::t('happycode', 'Add admin'); ?> </a> <?php echo GridView::widget(['dataProvider' => $admins, 'columns' => [['class' => \yii\grid\SerialColumn::className()], 'email', 'created', ['attribute' => 'created_by', 'format' => 'html', 'value' => function ($model) { if (!isset($model->createdBy)) { return Yii::t('happycode', 'root'); } return $model->createdBy->email; }], 'last_access']]);
use yii\helpers\Html; use ext\grid\GridView; use ext\grid\ActionColumn; use ext\grid\CheckboxColumn; use ext\Helper; use yii\grid\SerialColumn; $this->title = Yii::t('app', '用户'); $this->params['breadcrumbs'][] = ['label' => $this->title, 'url' => ['index']]; $this->params['breadcrumbs'][] = Yii::t('app', '用户列表'); $id = 'user-grid'; ?> <div class="row"> <div class="col-md-12 portlet light"> <?php echo GridView::widget(['id' => $id, 'title' => Yii::t('app', 'City'), 'moreActionsTemplate' => '{export}', 'actionsTemplate' => '{Create}{Delete}', 'actions' => ['Create' => function () { return Html::tag('a', '添加用户', ['class' => 'btn btn-primary', 'href' => Url::toRoute('create'), 'data-action' => 'get.modal']); }, 'Delete' => function () { return Html::tag('a', '删除用户', ['class' => 'btn btn-default', 'href' => Url::toRoute('multi-delete'), 'data-action' => 'confirm.multi.grid-view.modal', 'data-message' => '确认删除 <b>${num}</b> 记录? 删除后不可恢复!']); }], 'dataProvider' => $dataProvider, 'filterModel' => $filterModel, 'columns' => [['class' => SerialColumn::className()], ['class' => CheckboxColumn::className()], ['attribute' => 'id', 'label' => '编号'], ['attribute' => 'username', 'label' => '用户名'], ['attribute' => 'email', 'label' => '邮箱'], ['attribute' => 'zipcode', 'label' => '邮编'], ['attribute' => 'phone', 'label' => '电话号码'], ['attribute' => 'city', 'label' => '城市'], ['attribute' => 'state', 'label' => '国家'], ['attribute' => 'street', 'label' => '街道地址'], ['attribute' => 'created_at', 'label' => '创建时间', 'format' => 'datetime'], ['attribute' => 'status', 'label' => '状态', 'filter' => Dict::$userStatus, 'content' => function ($model, $key, $index, $column) { if ($model['status'] == Dict::USER_STATUS_FREEZE) { return '<span class="label label-sm label-danger">' . Dict::$userStatus[Dict::USER_STATUS_FREEZE] . '</span>'; } else { return '<span class="label label-sm label-success">' . Dict::$userStatus[Dict::USER_STATUS_NORMAL] . '</span>'; } }], ['class' => ActionColumn::className(), 'template' => '{view} {update}']]]); ?> </div> </div>
/** * Retrieves grid columns configuration using the modelClass. * @param Model $model * @param array $fields * @return array grid columns */ public function getIndexGridColumns($model, $fields) { /** @var ActiveController $controller */ $controller = $this->controller; $actionColumn = new ActionColumn(); $actionColumn->buttonOptions['class'] = 'operation-button'; $extraColumns = [['class' => \yii\grid\ActionColumn::className(), 'headerOptions' => ['class' => 'column-action'], 'controller' => Yii::$app->crudModelsMap[$model::className()], 'template' => '{update} {delete} {toggle}', 'buttons' => ['view' => function ($url, $model, $key) use($controller, $actionColumn) { if (!$controller->hasAccess('read', $model)) { return null; } return $actionColumn->buttons['view']($url, $model, $key); }, 'update' => function ($url, $model, $key) use($controller, $actionColumn) { if (!$controller->hasAccess('update', $model)) { return null; } return $actionColumn->buttons['update']($url, $model, $key); }, 'delete' => function ($url, $model, $key) use($controller, $actionColumn) { if (!$controller->hasAccess('delete', $model)) { return null; } return $actionColumn->buttons['delete']($url, $model, $key); }, 'toggle' => function ($url, $model, $key) use($controller, $actionColumn) { /** @var \yii\db\ActiveRecord $model */ if ($model->getBehavior('toggable') === null || !$controller->hasAccess('delete', $model)) { return null; } $enabled = $model->isEnabled(); $icon = '<span class="glyphicon glyphicon-' . ($enabled ? 'ban' : 'reply') . '"></span>'; $options = array_merge(['title' => $enabled ? Yii::t('app', 'Disable') : Yii::t('app', 'Enable'), 'aria-label' => $enabled ? Yii::t('app', 'Disable') : Yii::t('app', 'Enable'), 'data-pjax' => '0'], $enabled ? ['data-confirm' => Yii::t('app', 'Are you sure you want to disable this item?')] : [], $actionColumn->buttonOptions); return \yii\helpers\Html::a($icon, $url, $options); }]]]; if ($this->useSerialColumn) { $extraColumns[] = ['class' => \yii\grid\SerialColumn::className(), 'headerOptions' => ['class' => 'column-serial']]; } if ($this->useCheckboxColumn) { //$classParts = explode('\\', $this->modelClass); $extraColumns[] = ['class' => \yii\grid\CheckboxColumn::className(), 'headerOptions' => ['class' => 'column-checkbox'], 'multiple' => true]; } return array_merge($extraColumns, static::getGridColumns($model, $fields)); }
?> <div class="user-index"> <h2><?php echo Html::encode($this->title); ?> </h2> <hr> <p> <?php echo Html::a(Yii::t('user', 'Создать Пользователя'), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['id' => 'user-grid', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => CheckboxColumn::classname()], ['class' => SerialColumn::className()], ['attribute' => 'username', 'format' => 'html', 'value' => function ($model) { return Html::a($model['username'], ['view', 'id' => $model['id']]); }], 'email', ['attribute' => 'role', 'value' => function ($model) { return $model->Role; }, 'filter' => Html::activeDropDownList($searchModel, 'role', $roleArray, ['class' => 'form-control', 'prompt' => Yii::t('user', 'Роль')])], ['attribute' => 'status', 'format' => 'html', 'value' => function ($model) { if ($model->status === $model::STATUS_ACTIVE) { $class = 'label-success'; } elseif ($model->status === $model::STATUS_INACTIVE) { $class = 'label-warning'; } else { $class = 'label-danger'; } return '<span class="label ' . $class . '">' . $model->Status . '</span>'; }, 'filter' => Html::activeDropDownList($searchModel, 'status', $statusArray, ['class' => 'form-control', 'prompt' => Yii::t('user', 'Выберите статус')])], ['attribute' => 'created_at', 'format' => ['date', 'd.m.Y']], ['class' => ActionColumn::className(), 'header' => Yii::t('user', 'Управление')]]]); ?>
/** * Format same as GridView::$columns * @param ActiveRecord $model * @return array * * @see GridView::$columns */ public function getTableColumns($model) { $attributes = $model->getAttributes(); foreach ($model->getTableSchema()->primaryKey as $pk) { unset($attributes[$pk]); } $columns = array_keys($attributes); if (!array_intersect(['update', 'delete'], $this->disabledActions)) { $columns[] = $this->getActionColumn(); } array_unshift($columns, ['class' => SerialColumn::className(), 'contentOptions' => ['class' => 'action-column']]); return $columns; }
<?php use yii\helpers\Url; use yii\helpers\Html; use ext\grid\GridView; use ext\grid\ActionColumn; use ext\grid\CheckboxColumn; use ext\Helper; use yii\grid\SerialColumn; $this->title = Yii::t('app', '城市'); $this->params['breadcrumbs'][] = ['label' => $this->title, 'url' => ['index']]; $this->params['breadcrumbs'][] = Yii::t('app', '城市列表'); $id = 'City-grid'; ?> <div class="row"> <div class="col-md-12 portlet light"> <?php echo GridView::widget(['id' => $id, 'title' => Yii::t('app', 'City'), 'moreActionsTemplate' => '{export}', 'actionsTemplate' => '{Create}{Delete}', 'actions' => ['Create' => function () { return Html::tag('a', '添加城市', ['class' => 'btn btn-primary', 'href' => Url::toRoute('create'), 'data-action' => 'get.modal']); }, 'Delete' => function () { return Html::tag('a', '删除城市', ['class' => 'btn btn-default', 'href' => Url::toRoute('multi-delete'), 'data-action' => 'confirm.multi.grid-view.modal', 'data-message' => '确认删除 <b>${num}</b> 记录? 删除后不可恢复!']); }], 'dataProvider' => $dataProvider, 'filterModel' => $filterModel, 'columns' => [['class' => SerialColumn::className()], ['class' => CheckboxColumn::className()], ['attribute' => 'id', 'label' => '编号'], ['attribute' => 'name', 'label' => '城市名称'], ['attribute' => 'create_time', 'label' => '创建时间', 'format' => 'datetime'], ['attribute' => 'update_time', 'label' => '修改时间', 'format' => 'datetime'], ['class' => ActionColumn::className(), 'template' => '{update}', 'buttons' => ['update' => function ($url, $model, $key) { $options = ['title' => Yii::t('yii', 'update'), 'href' => $url, 'data-action' => 'get.modal']; return Html::tag('a', '<i class="fa fa-pencil"></i>', $options); }]]]]); ?> </div> </div>
<br/> <div class="col-md-5">Due amount:</div> <div class="col-md-4"><?php echo \Yii::$app->ecom->formatter->asPrice($order->due_amount); ?> </div> <br/> <div class="col-md-5">Customer #:</div> <div class="col-md-4"><?php echo $order->user_id; ?> </div> <br/> <h4>Order items</h4> <?php echo \opus\ecom\widgets\GridView::widget(['dataProvider' => new ActiveDataProvider(['query' => $order->getOrderLines()->with('product'), 'pagination' => false]), 'columns' => [['class' => \yii\grid\SerialColumn::className()], 'product.name', 'quantity', 'due_amount:price']]); if ($order->status === 'new') { echo Html::a('Go to payment', ['payment/pay', 'orderId' => $order->id], ['class' => 'btn btn-lg btn-danger']); } ?> </div> <div class="row col-lg-offset-4 "> <h4>Invoices</h4> <?php echo \opus\ecom\widgets\GridView::widget(['dataProvider' => new ActiveDataProvider(['query' => $order->getInvoices(), 'pagination' => false]), 'columns' => [['class' => \yii\grid\SerialColumn::className()], 'due_amount:price:Amount', 'due_datetime:datetime:Deadline', 'created:datetime:Created']]); echo Html::a('Issue a new invoice', ['order/new-invoice', 'orderId' => $order->id], ['class' => 'btn btn-lg btn-success']); ?> </div>
use pistol88\order\assets\OrdersListAsset; use pistol88\order\widgets\AssigmentToOrder; $this->title = yii::t('order', 'Orders'); $this->params['breadcrumbs'][] = $this->title; Asset::register($this); OrdersListAsset::register($this); if ($dateStart = yii::$app->request->get('date_start')) { $dateStart = date('Y-m-d', strtotime($dateStart)); } if ($dateStop = yii::$app->request->get('date_stop')) { $dateStop = date('Y-m-d', strtotime($dateStop)); } $timeStart = yii::$app->request->get('time_start'); $timeStop = yii::$app->request->get('time_stop'); $columns = []; $columns[] = ['class' => \yii\grid\SerialColumn::className()]; $columns[] = ['attribute' => 'id', 'options' => ['style' => 'width: 49px;'], 'contentOptions' => ['class' => 'show-details']]; $columns[] = ['attribute' => 'count', 'label' => yii::t('order', 'Cnt'), 'contentOptions' => ['class' => 'show-details'], 'content' => function ($model) { return $model->count; }]; $columns[] = ['attribute' => 'base_cost', 'label' => yii::$app->getModule('order')->currency, 'contentOptions' => ['class' => 'show-details']]; $columns[] = ['attribute' => 'cost', 'label' => '%', 'contentOptions' => ['class' => 'show-details'], 'content' => function ($model) { $total = $model->cost; if ($model->promocode) { $total .= Html::tag('div', $model->promocode, ['style' => 'color: orange; font-size: 80%;', yii::t('order', 'Promocode')]); } return $total; }]; foreach (Yii::$app->getModule('order')->orderColumns as $column) { if ($column == 'payment_type_id') { $column = ['attribute' => 'payment_type_id', 'filter' => Html::activeDropDownList($searchModel, 'payment_type_id', $paymentTypes, ['class' => 'form-control', 'prompt' => Yii::t('order', 'Payment type')]), 'contentOptions' => ['class' => 'show-details'], 'value' => function ($model) use($paymentTypes) {
echo Html::submitButton("", ['class' => 'btn btn-sm yellow fa fa-search ', 'title' => Yii::$app->params['lang']['button_search']]); ?> </div> </div> </div> <?php $form->end(); ?> <?php ?> <?php echo \kartik\grid\GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $model, 'columns' => [['class' => SerialColumn::className()], ['class' => \kartik\grid\CheckboxColumn::className()], 'user_id', 'user_name', 'email', ['class' => CheckboxColumn::className(), 'class' => DataColumn::className(), 'attribute' => 'is_validated', 'format' => 'html', 'value' => function ($model) { return $this->render('list_item.php', ['model' => $model, 'action' => 'is_validated']); }], 'user_money', 'frozen_money', 'rank_points', 'pay_points', 'reg_time', ['class' => DataColumn::className(), 'format' => 'html', 'attribute' => Yii::$app->params['lang']['handler'], 'value' => function ($model) { return $this->render('list_item.php', ['model' => $model, 'action' => 'handler']); }]]]); ?> </div> </div>
<?php use yii\helpers\Html; use yii\grid\GridView; use app\modules\tasks\widgets\TasksListWidget; use yii\grid\SerialColumn; /* @var $this yii\web\View */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Результаты'; $this->params['breadcrumbs'][] = $this->title; ?> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => SerialColumn::className()], ['attribute' => 'logo', 'format' => 'raw', 'value' => function ($data) { return $data->user->getLogo(); }], 'result', 'login', 'university', 'city']]);