简体   繁体   English

YII2-index.php中的列过滤器不起作用

[英]YII2 - Column filter in index.php won't work

I've modified the index.php to show name instead the id's. 我已经修改了index.php以显示名称而不是ID。

This is my orders/index.php 这是我的订单/ 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? 在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'),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM