2017-12-14 19 views
0

というテーブルからGiiを使用してモデルとそのCRUDを作成しました。です。そのindex.phpは、列1列3と呼ばれる2つの列を持つGridViewを持っています。次にという人物という列を追加しました。これは人のテーブルから来ました。Yii2:モデルに属していないGridViewの列を並べ替える方法

GridView

問題は、列がソート可能ではないということです。

だから私はこのテーブル(が彼らのテーブルの主キーですPERSON_IDとをcolumn1_id)している:

vacations: column1_id, column3. 
persons: person_id, person_name, column1_id. 

は、たぶん私はVacationsSearchファイルで何かを追加する必要があります。

+1

利用関係をシナリオ2を参照することができますが、より広い説明のための関連コラム

$dataProvider->setSort([ ..... 'your_related_column' => [ 'asc' => ['related_table.your_related_column' => SORT_ASC], 'desc' => ['related_table.your_related_column' => SORT_DESC], 'label' => 'Your Label' ] ] ]); ..... // filter by country name $query->joinWith(['yor_relation' => function ($q) { $q->where('related_table.your_related_column LIKE "%' . $this->yourRelatedAttribute . '%"'); }]); 

のクエリを追加するための機能を検索し、並べ替え拡張する必要があります。 http://www.yiiframework.com/forum/index.php/topic/32188-cgridview-to-display-data-from-two-tables/ –

答えて

関連する問題