Answer the question
In order to leave comments, you need to log in
How to use date-range outside GridView?
Good afternoon. There is a task - to connect possibility of a choice of a time interval for display of records. I use . You need to display the widget on a regular non-index page with a grid view. As I understand it, I can pass $searchModel to any page , which looks like this
public $createTimeRange;
public $createTimeStart;
public $createTimeEnd;
public function behaviors()
{
return [
[
'class' => DateRangeBehavior::className(),
'attribute' => 'createTimeRange',
'dateStartAttribute' => 'createTimeStart',
'dateEndAttribute' => 'createTimeEnd',
]
];
}
public function rules()
{
return [
[['createTimeRange'], 'match', 'pattern' => '/^.+\s\-\s.+$/'],
[['createTimeStart', 'createTimeEnd'], 'date', 'format' => 'php:Y-m-d']
];
}
$query->andFilterWhere(['>=', 'date_begin', $this->createTimeStart])
->andFilterWhere(['<=', 'date_end', $this->createTimeEnd]);
<?=DateRangePicker::widget([
'model'=>$searchModel,
'attribute'=>'createTimeRange',
'convertFormat'=>true,
'startAttribute'=>'createTimeStart',
'endAttribute'=>'createTimeEnd',
'pluginOptions'=>[
'timePicker'=>true,
'timePickerIncrement'=>7,
'locale'=>[
'format'=>'Y-m-d h:i A'
]
]
]); ?>
Answer the question
In order to leave comments, you need to log in
In addition to the widget, you also need a form that will send the data. The GridView has a js script that sends a get request when the data changes, but the widget itself does not send anything. Add a js submit script or insert a widget into the form.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question