2017-12-14 2 views
0

이라는 테이블에서 Gii를 사용하여 모델과 CRUD를 만들었습니다.. index.php에는 열 1열 3이라는 두 개의 열이있는 GridView가 있습니다. 그런 다음 이라는 이름의 열을 이라는 테이블에서 가져 왔습니다.Yii2 : 모델에 속하지 않는 GridView의 열을 정렬하는 방법

GridView

문제는 열 사람가 정렬되지 않는 것입니다.

그래서 나는이 테이블이 (을 column1_id 및 가 테이블의 기본 키입니다 person_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/ –

답변

관련 문제