在Yii2中过滤Kartik Grid中的已连接列

时间:2016-02-25 06:31:26

标签: yii2

当我过滤表的一列时,它工作正常。请告诉我如何搜索已连接的列。在下面的屏幕截图中,Manager是一个连接列。 Manager是parties.name_manager的别名。父视图和子视图都是一样的。我正在使用Kartik Grid。 Kartik Grid

这是我的父母

的index.php
<?php

use yii\helpers\Html;
use kartik\grid\GridView;
use backend\modules\managerproductsalesmonthly\models\ProductsalesdetailsSearch;

/* @var $this yii\web\View */
/* @var $searchModel backend\modules\managerproductsalesmonthly\models\ProductsalesSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Productsales';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="productsales-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <!-- <p>
        <?= Html::a('Create Productsales', ['create'], ['class' => 'btn btn-success']) ?>
    </p> -->

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'export' => false,
        'columns' => [
            [
                'class' => 'kartik\grid\ExpandRowColumn',
                'value' => function($model, $key, $index, $column){
                return GridView::ROW_COLLAPSED;
            },
                'detail' => function($model, $key, $index, $column){
                $searchModel = new ProductsalesdetailsSearch();               
                $searchModel-> productname = $model->productname;
                //$searchModel-> total = $model->total;
                $searchModel-> manager = $model->manager;
                $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

                return Yii::$app->controller->renderPartial('_productsales', [
                    'searchModel' => $searchModel,
                    'dataProvider' => $dataProvider,
                    ]);                   

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

            // 'id',
            // 'productsales_ebillid',
            // 'year',
            // 'console',
            // 'billno:ntext',
            [
             'attribute' => 'manager',
             'value' => 'productsalesPartyname.name_manager'
            ],
            //'billdate',
            // 'productsales_partyname',
            // 'itemid',
            'productname',
            // 'batchno',
            // 'expdate',
            // 'mrp',
            // 'rate',
            // 'productiondate',
            // 'prodqty',
            // 'qty',
            // 'free',
            'total',
            // 'discount',

            //['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>

</div>

1 个答案:

答案 0 :(得分:0)