A
A
AlexSer2018-03-17 09:21:46
Yii
AlexSer, 2018-03-17 09:21:46

Why doesn't the search box appear in gridview?

Hello! I'm trying to do filtering in the gridview but for some reason the search field does not appear in the column where the related data is displayed. Namely, where I display the Surname! Do not tell 5aacb47e34409832474111.jpegme what could be the problem?
Perhaps something is wrong in the search model? (I'm not sure)

<?php

namespace frontend\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;

use frontend\models\History;

/**
 * SearchPacients represents the model behind the search form of `frontend\models\History`.
 */
class SearchPacients extends History
{
    public  $family;
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'pacient_id', 'standart_id', 'doctor_id', 'otdelenie_id', 'status_id', 'type_analiz_id', 'organization_id', 'napravlenie_id', 'lu'], 'integer'],
            [['date','family' ,'date_close'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = History::find();
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $dataProvider->setSort([
            'attributes' => [
                'id',
                'family' => [
                    'label' => 'Full Name',
                    'default' => SORT_ASC
                ],
            ]
        ]);

        if (!($this->load($params) && $this->validate())) {
            /**
             * Жадная загрузка данных модели Страны
             * для работы сортировки.
             */
            $query->joinWith(['pacients']);
            return $dataProvider;
        }

        //$this->addCondition($query, 'id');
     //   $this->addCondition($query, 'family', true);




        // Фильтр по стране
        $query->joinWith(['pacients' => function ($q) {
            $q->where('pacients.family LIKE "%' . $this->family. '%"');
        }]);

        return $dataProvider;
    }
}

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
D
Dmitry, 2018-03-17
@AlexSer

Good morning.
It is necessary to slightly rewrite the output of the column with the last name.
Something like this

[
   'attribute' => 'family',
   'value' => 'pacient.family'
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question