GridView and Foreign Key


I have a table “procedimiento” who has a foreign key to table “organizacion”. I have generated CRUD code with gii. I got a GridView working fine for table “procedimiento”. I’m able to show “organizacion” fields using this code (see “$data->organizacion0->nombre” reference):

    <?= GridView::widget([

        'dataProvider' => $dataProvider,

        'filterModel' => $searchModel,

        'columns' => [

            ['class' => 'yii\grid\SerialColumn'],





                'header' => 'Responsable',

                'value' => function ($data) {

                    return $data->organizacion0->nombre;




            ['class' => 'yii\grid\ActionColumn'],


    ]); ?> 

but I can not search in this column. I found some links with useful information for Yii 1.1 but nothing for Yii 2.

You should include


in public method "search" (procedimientoSearch model).


Thanks Antonio. Finally I found this link:

and Search is working… but not sorting. I continue to investigate.