I
I
Iossarian2019-04-10 09:53:24
Yii
Iossarian, 2019-04-10 09:53:24

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]);

And in the view I call the widget
<?=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'
            ]
        ]
    ]); ?>

But, accordingly, nothing happens. Perhaps I'm confusing the passed attributes? The bottom line is that I need to give the user a choice of the period from Monday to Sunday and by default show records for the past week. There are 2 fields in the database - date_begin and date_end . Fields are required for substitution in the Word template. And here on these fields I should filter an output of records.

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
M
Maxim Timofeev, 2019-04-11
@webinar

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 question

Ask a Question

731 491 924 answers to any question