H
H
hollanditkzn2018-02-19 16:13:32
Yii
hollanditkzn, 2018-02-19 16:13:32

Why is data not filtered by date in gridview?

I do not understand why they are not filtered by date. It seems that they are in the get link, but it seems that they are not there. I can't understand why.
My implementation in gridview

use kartik\datecontrol\DateControl;
...
[
                    'attribute' => 'date_birth',
                    'format' => 'date',
                    'filter' => DateControl::widget([
                        'model' => $searchModel,
                        'name' => 'date_birth',
                        'autoWidget' => true,
                        'type' => DateControl::FORMAT_DATE,
                        'displayFormat' => 'yyyy-MM-dd'
                    ])
                ],
....

searchModel
<?php
...
class UserSearch extends User
{
    public $nameEmployee;
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'id_position', 'status', 'created_at', 'updated_at'], 'integer'],
            [[... 'date_birth'], '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 = User::find()->where(['active' => User::WORK]);

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'id_position' => $this->id_position,
            'date_birth' => $this->date_birth,
            ...
        ]);

        return $dataProvider;
    }
}

And I get this link
http://hosttraining/frontend/web/index.php?UserSearch%5Bid%5D=&UserSearch%5Busername%5D=&UserSearch%5BnameEmployee%5D=&date_birth-w1-disp=2018-02-21&date_birth=2018-02-21&UserSearch%5Bid_position%5D=&UserSearch%5Bcreated_at%5D=&r=user%2Findex

But at the same time it does not find anything and does not write that there are no records

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
H
hollanditkzn, 2018-02-19
@hollanditkzn

replace name with attribute

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question