Answer the question
In order to leave comments, you need to log in
How to properly organize search by date range in yii2?
view.
<?php
/* @var $this yii\web\View */
/* @var $searchModel app\models\ZakazSearch */
use yii\helpers\Html;
use kartik\grid\GridView;
use yii\helpers\ArrayHelper;
use yii\data\ActiveDataProvider;
use frontend\models\NumberColumn;
use kartik\widgets\DateTimePicker;
$dataProvider = new ActiveDataProvider([
'query' => \app\models\Zakaz::find()
->where('action <= 0') ->andWhere(['>=', 'date_close', '2018-08-01 00:00:00'])->
andWhere(['<=', 'date_close', '2018-09-17 00:00:00']),
'pagination' => [
'pageSize' => 10,
],
]);
?>
<?php $date_yesterday = new DateTime('-1 day');
echo GridView::widget([
'dataProvider' => $dataProvider,
'showFooter' => true,
'filterModel'=>$searchModel,
'showPageSummary'=>false,
'pjax'=>true,
'striped'=>true,
'hover'=>true,
'panel'=>['type'=>'primary', 'heading'=>$date_yesterday->format('d-M')],
'columns' => [
[
'attribute' => 'date_close',
],
[
'attribute' => 'id_zakaz',
],
[
'attribute' => 'description',
],
[
'attribute' => 'fact_oplata',
],
[
'attribute' => 'id_shop',
'value'=> function ($model) {
switch ($model->id_shop) {
case 2;
return 'Московский';
case 5;
return 'Админ';
case 6;
return 'Пушкина';
case 9;
return 'Сибирский';
case 12;
return 'Четаева';
case 16;
return 'Маркса';
}
return null;
}
],
],
]);;?>
$dataProvider = new ActiveDataProvider([
'query' => \app\models\Zakaz::find()
->where('action <= 0') ->andWhere(['>=', 'date_close', '2018-08-01 00:00:00'])
->andWhere(['<=', 'date_close', '2018-09-17 00:00:00']),
'pagination' => [
'pageSize' => 10,
],
]);
Answer the question
In order to leave comments, you need to log in
I'm thinking of adding 2 DatePicker fields to select dates, and so do the selection by date range.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question