DatePicker in GridVIew


(KevinSmash) #1

Hi, I tried to realize DatePicker in GridView, but I have no search in a column where DatePicker has to work. Also tried that when pressing on strochkumozhno was to choose date in the form of the calendar, but only the first line is allocated.

View
[
‘attribute’ => ‘date_subscription’,
‘filter’ => \yii\jui\DatePicker::widget([
‘model’=>$searchModel,
‘language’ => ‘ru’,
‘dateFormat’ => ‘yyyy-MM-dd’,
‘options’ => [
‘class’ => ‘form-control’,
‘autocomplete’ => ‘off’,
]
]),
‘value’ => function ($model, $key, $index) {
return \yii\jui\DatePicker::widget([
‘model’ => $model,
‘attribute’ => ‘date_subscription’,
]);
},
‘format’ => ‘raw’
],`

ModelSearch

public $date_subscription;

public function rules()

 ['date_subscription', 'default', 'value' => null],

if ($this->date_subscription !== null) {
        $date_subscription = strtotime($this->date_subscription);
        $query->andFilterWhere(['between', 'date_subscription', $date_subscription, $date_subscription + 3600 * 24]);
    }

Model

public function beforeValidate() {
    if ($this->date_subscription !== null) {
        $this->date_subscription= strtotime($this->date_subscription);
    }
    return parent::beforeValidate();
}