【问题标题】:yii2 - Use a second model in a GridView to build a dropdown menu in a columnyii2 - 在 GridView 中使用第二个模型在列中构建下拉菜单
【发布时间】:2017-02-14 22:12:43
【问题描述】:

我有两张桌子:

tb_employee('employeeID', 'firstName', 'lastName', 'departmentID')

tb_skills('skillID', 'week', 'ser', 'skillKnowledge','proficiency', 'instructorID').

在技能视图中,我在instructorID 列中没有任何值,因为我想要用下拉菜单填充它,其中包含departmentID=20 的所有员工名字,以便用户可以选择他们想要的导师。但是,我不知道该怎么做,这是我的代码:

 <?= GridView::widget([
    'dataProvider' => $dataProvider,
  //  'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],

        'skillID',
        'week',
        'ser',
        'skillKnowledge:ntext',
        'proficiency:ntext',
        [
                'attribute' => 'instructorID',
                'value' => Html::activeDropDownList($searchModel, 
                    'instructorID', ArrayHelper::map(app\models\TbEmployee::find()->asArray()->all(), 'employeeID', 'firstName'),
                        ['class'=>'form-control','prompt' => 'Select']),
        ],  

]); ?>

【问题讨论】:

  • 您想使用下拉菜单过滤gridview中显示的行吗?

标签: php yii yii2 yii-extensions yii2-basic-app


【解决方案1】:

如果您想使用下拉菜单进行过滤,您应该使用“过滤器”属性

'attribute' => 'attribute_name',
'filter' => Html::activeDropDownList($searchModel, 
    'attribute_name',
     ArrayHelper::map(ModelName::find()->asArray()->all(), 'employeeID', 'firstName'),
                     ['class'=>'form-control','prompt' => 'Select']),

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多