yii2网格视图搜索,排序,过滤两个表

时间:2015-03-25 05:15:09

标签: yii2

如何在yii2网格视图中搜索,排序和过滤两个表?从gii工具生成后,我搜索了一个表列的排序,但我必须对另一个表的列应用搜索,排序和过滤。

 <?= 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 个答案:

答案 0 :(得分:-1)

尝试使用:

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