tklustig
(Kipp Thomas)
July 22, 2017, 1:04pm
1
Following code reads out value of foreign key in lookup-table correctly,but it fails in combobox using Kartik-Widget GridView/Select2. Any ideas,how to fix this problem?
.
.
.
[
'attribute' => 'rechtsart',
'label' => Yii::t('app', 'Rechtsart'),
'value' => function($model){
if ($model->rechtsart0)
{return $model->rechtsart0->art;}
else
{return NULL;}
},
'filterType' => GridView::FILTER_SELECT2,
'filter' => \yii\helpers\ArrayHelper::map(\app\models\Rechtsform::find(['id_recht' => 'value'])->orderBy(['id_recht' => SORT_ASC])->asArray()->all(), 'id_recht', 'rechtsart0.art'),
'filterWidgetOptions' => [
'pluginOptions' => ['allowClear' => true],
],
'filterInputOptions' => ['placeholder' => 'Rechtsform', 'id' => 'grid-bewerbungen-search-rechtsart']
],...
I get no values at all in Combobox.
Following code will get naked values, but this is not very useful,isn’t it?
.
.
.
'filter' => \yii\helpers\ArrayHelper::map(\app\models\Rechtsform::find(['id_recht' => 'value'])->orderBy(['id_recht' => SORT_ASC])->asArray()->all(), 'id_recht', 'id_recht'),...
jkofsky
(Jkofsky)
July 24, 2017, 3:19am
2
tklustig:
Following code reads out value of foreign key in lookup-table correctly,but it fails in combobox using Kartik-Widget GridView/Select2. Any ideas,how to fix this problem?
.
.
.
[
'attribute' => 'rechtsart',
'label' => Yii::t('app', 'Rechtsart'),
'value' => function($model){
if ($model->rechtsart0)
{return $model->rechtsart0->art;}
else
{return NULL;}
},
'filterType' => GridView::FILTER_SELECT2,
'filter' => \yii\helpers\ArrayHelper::map(\app\models\Rechtsform::find(['id_recht' => 'value'])->orderBy(['id_recht' => SORT_ASC])->asArray()->all(), 'id_recht', 'rechtsart0.art'),
'filterWidgetOptions' => [
'pluginOptions' => ['allowClear' => true],
],
'filterInputOptions' => ['placeholder' => 'Rechtsform', 'id' => 'grid-bewerbungen-search-rechtsart']
],...
I get no values at all in Combobox.
Following code will get naked values, but this is not very useful,isn’t it?
.
.
.
'filter' => \yii\helpers\ArrayHelper::map(\app\models\Rechtsform::find(['id_recht' => 'value'])->orderBy(['id_recht' => SORT_ASC])->asArray()->all(), 'id_recht', 'id_recht'),...
What are the columns in the Rechtsform table? Are you asking for fields that aren’t there? Another thing you could do is in the ‘Rechtsform’ model and a method.
/**
* get list of Rechtsform for dropdown
*/
public static function getRechtsformList() {
$droptions = Rechtsform::find()->asArray()->all();
return ArrayHelper::map($droptions, 'id', 'value');
}
Then your ‘filter’ could be
'filter' => Rechtsform::getRechtsformList(),
tklustig
(Kipp Thomas)
July 25, 2017, 11:06am
3
jkofsky:
What are the columns in the Rechtsform table? Are you asking for fields that aren’t there? Another thing you could do is in the ‘Rechtsform’ model and a method.
/**
* get list of Rechtsform for dropdown
*/
public static function getRechtsformList() {
$droptions = Rechtsform::find()->asArray()->all();
return ArrayHelper::map($droptions, 'id', 'value');
}
Then your ‘filter’ could be
'filter' => Rechtsform::getRechtsformList(),
Thx.Your hints helped solving my problem. Ur the Greatest!
jkofsky
(Jkofsky)
July 27, 2017, 4:37am
4
Glad to help. If my answer didn’t actually answer your question, posting your solution could help others