0
votes

How to searching ,sorting ,filtering for two table in yii2 grid view? after generating from gii tool ,i got searching sorting for one table columns but i have to apply searching ,sorting ,filtering on columns of another table.

 <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'username',

            // 'account_activation_token',
             'email:email',
             'profile.name',
             [       
                'attribute' => 'name',
        'value' => 'profile.name',
        'enableSorting' => true,
         //here i want to use the filter option just like in yii 1.1 but i dont know how to use the textbox search in yii2.0 
        ],
            // 'usertype',
            // 'status',
            // 'created_at',
            // 'updated_at',

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
1
Are you wanting to use data from related records in another table? - Joe Miller
Please take some effort to google it first. Here is the link: yiiframework.com/wiki/653/… - Chinmay Waghmare
@JoeMiller yes i am using data from another table and need to apply textbox searching on them and i already googled but there is no example for two table records. - santosh
@chinmay i have done lot of goole here and use [ 'attribute' => 'name', 'value' => 'profile.name', 'enableSorting' => true, ], this code, but i am not geet text box and sort - santosh
Can you show the code what you tried so far? Where exactly you are facing the problem. - Chinmay Waghmare

1 Answers

-1
votes

Try Using:

 [       
        'attribute' => 'name',
        'value' => 'profile.name',
        'enableSorting' => true,
        'filter' => function($model){
                return Html::activeTextInput($searchModel, $this->name),
         }
 ],