I've modified the index.php to show name instead the id's.
This is my orders/index.php
<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use yii\helpers\ArrayHelper;
use frontend\models\Statuses;
$this->title = Yii::t('app', 'Ordini');
$this->params['breadcrumbs'][] = $this->title;
$user = Yii::$app->user->identity;
?>
<div class="orders-index">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?php
if ($user->role == 10 || $user->role > 40)
echo Html::a(Yii::t('app', 'Nuovo'), ['create'], ['class' => 'btn btn-success']);
?>
</p>
<?php Pjax::begin(); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
['attribute'=>'customer_id', 'value'=>'CustomersName',],
['attribute'=>'product_id', 'value'=>'ProductsName',],
'date',
[
'attribute'=>'status_id',
'value'=>'StatusesName',
'filter' => Html::activeDropDownList($searchModel, 'status_id', ArrayHelper::map(Statuses::find()->asArray()->all(), 'id', 'name'),['class'=>'form-control','prompt' => 'Select Category']),
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
<?php Pjax::end(); ?></div>
Filter doesn't work. I've tryed with dropdown or only number with no success. I don't know how to check where it fail!
In OrdersSearch? In the model or controller?
Thank you
You don't have to provide the whole code for the dropdown field. This should be enough:
'filter' => ArrayHelper::map(Statuses::find()->asArray()->all(), 'id', 'name'),