Answer the question
In order to leave comments, you need to log in
How to filter data by two dates with ModelSearch in Yii2?
There is a data model in which there is a date_start field.
It is necessary to implement filtering by date range (between).
For the datepicker, I installed the kartik extension.
The widget code is as follows
<div class="container">
<div class="col-md-6">
<?='<label class="control-label">Valid Dates</label>';?>
<?= DatePicker::widget([
'name' => 'from_date',
'type' => DatePicker::TYPE_RANGE,
'name2' => 'to_date',
'options' => ['placeholder' => 'Start date','class' => 'datepicker'],
'options2' => ['placeholder' => 'End date', 'class' => 'datepicker'],
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy/mm/dd'
]
]);
?>
</div>
</div>
Answer the question
In order to leave comments, you need to log in
There are small shifts, filtering has been achieved.
1. Widget with datepickers moved to GridView
[
'attribute' => 'date_start',
'label' => 'Date start',
'filter' => DatePicker::widget([
'name' => 'CampaignSearch[from_date]',
'type' => DatePicker::TYPE_RANGE,
'name2' => 'CampaignSearch[to_date]',
'options' => ['placeholder' => 'Start date','class' => 'datepicker'],
'options2' => ['placeholder' => 'End date', 'class' => 'datepicker'],
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy/mm/dd',
]
]),
],
public $from_date;
public $to_date;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question