Не могу добиться работы виджета в фильтре. Код в GridView:
[
'label' => Yii::t('app', 'Дата'),
'attribute' => 'document_date',
'format' => 'raw',
'filter' => DatePicker::widget([
'attribute' => 'date_from',
'attribute2' => 'date_to',
'type' => DatePicker::TYPE_RANGE,
'model' => $searchModel,
'separator' => '-',
'convertFormat' => true,
'pluginOptions' => [
'todayHighlight' => true,
'weekStart'=>1, //неделя начинается с понедельника
'autoclose' => true,
'format' => 'dd.MM.yyyy'
],
'readonly' => true
]),
'value' => function($model){
$time = strtotime($model->document_date);
return Yii::t('app', 'от').' '.date('d.m.Y', $time).'<br><span class="text-muted">'.date('H:i:s', $time).'</span>';
},
'headerOptions' => ['class' => 'text-center','style'=>'width: 320px;'],
'contentOptions' =>['class' => 'text-center'],
],
В модели добавил:
public $date_from;
public $date_to;
В серч модели:
if ($this->document_date){
$timestampFrom = strtotime($this->date_from);
$timestampTo = strtotime($this->date_to);
if ($timestampFrom && $timestampTo){
$dateFrom = date("Y-m-d 00:00:00", $timestampFrom);
$dateTo = date("Y-m-d 23:59:59", $timestampTo);
$query
->andFilterWhere(['<=', 'orders.document_date', $dateTo])
->andFilterWhere(['>=', 'orders.document_date', $dateFrom])
;
}
}
При установке даты в любую часть виджета, она подставляется и в date_from и в date_to. Что я не так делаю?