yii2グリッドビューのテーブルでは、アルファベット順の並べ替えに使用する[1 => car、2 => motobike、3 =>フェリー]古典的な関係の)。配列をグリッドビュー(Yii2)の並べ替え基準として使用する
これをデータプロバイダで設定するにはどうすればよいですか?どんな助けでも大歓迎です!
<?= GridView::widget([
'dataProvider' => $dataProvider,
// 'filterModel' => $searchModel,
'tableOptions' => ['class' => 'table'],
'layout'=>"{summary}\n<div class='rounded'>{items}</div>\n{pager}",
'summary' => "Zeige {begin} - {end} von {totalCount} Ideen",
'columns' => [
'id',
[
'attribute' => 'art',
'value' => function ($model) {
$arten = \Yii::$app->params['ideenArten']; //[1=>car, 2=>bike, 3=>scooter etc]
return $arten[$model->art];
},
'label' => 'Kategorie',
'filter' => Html::activeDropDownList($searchModel, 'art', \Yii::$app->params['ideenArten'],['class'=>'form-control','prompt' => 'Select Type']),
],
],
]); ?>
そして、私は関係で正常にいくつかの他のフィールドのソート設定どこ私の検索モデルは以下の通りです:
public function search($params)
{
$query = Idee::find();
// add conditions that should always apply here
$query->joinWith(['authorprofile']);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$dataProvider->sort->attributes['authorprofile'] = [
// The tables are the ones our relation are configured to
// in my case they are prefixed with "tbl_"
'asc' => ['user_profile.lastname' => SORT_ASC],
'desc' => ['user_profile.lastname' => SORT_DESC],
];
$dataProvider->sort->attributes['art'] = [
'asc' => ['user_profile.lastname' => SORT_ASC],
'desc' => ['user_profile.lastname' => SORT_DESC],
];
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'art' => $this->art,
'status' => $this->status,
'projektstart' => $this->projektstart,
'projektende' => $this->projektende,
'created_by' => $this->created_by,
'updated_by' => $this->updated_by,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]);
$query->andFilterWhere(['like', 'title', $this->title])
->andFilterWhere(['like', 'body', $this->body])
->andFilterWhere(['or',
['like', 'user_profile.firstname', $this->authorprofile],
['like', 'user_profile.lastname', $this->authorprofile],
]);
return $dataProvider;
}
とコントローラのコードは次のとおりです。
public function actionSpeicher()
{
$lastIdea = Idee::find()->orderBy("updated_at DESC")->one();
$searchModel = new IdeeSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'lastIdea' => $lastIdea,
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
updateあなたの質問gridviewのコードを追加すると、関連するコントローラ/アクションコード.. pelase – scaisEdge
こんにちはscaisEdge、私の最初の投稿に私のgridviewコード(関連部分)が追加されました – dave3011