2017 © Pedro Peláez
 

yii2-extension yii2-daterangepicker

Date Range Picker widget for Yii2

image

hiqdev/yii2-daterangepicker

Date Range Picker widget for Yii2

  • Friday, May 18, 2018
  • by hiqdev
  • Repository
  • 3 Watchers
  • 6 Stars
  • 747 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 217 % Grown

The README.md

Yii2 Date Range Picker

Date Range Picker widget for Yii2, (*1)

Latest Stable Version Total Downloads Build Status Scrutinizer Code Coverage Scrutinizer Code Quality Dependency Status, (*2)

This widget renders a DateRangePicker input control using Bootstrap Date Range Picker widget., (*3)

Installation

The preferred way to install this yii2-extension is through composer., (*4)

Either run, (*5)

php composer.phar require "hiqdev/yii2-daterangepicker"

or add, (*6)

"hiqdev/yii2-daterangepicker": "*"

to the require section of your composer.json., (*7)

Usage

There are two ways of using this widget: with an ActiveForm instance or as a widget setting up its model and attribute. Additional options could be passed in 'clientOptions' array., (*8)

With an ActiveForm

pickerOptions = ArrayHelper::merge([
    'class' => DateRangePicker::class,
    'name' => '',
    'options' => [
        'tag' => false,
        'id' => "{$id}-period-btn",
    ],
    'clientEvents' => [
        'apply.daterangepicker' => new JsExpression(/** @lang JavaScript */"
            function (event, picker) {
                var form = $(picker.element[0]).closest('form');
                var span = form.find('#{$id}-period-btn span');

                span.text(picker.startDate.format('ll') + ' - ' + picker.endDate.format('ll'));

                form.find('input[name=from]').val(picker.startDate.format());
                form.find('input[name=till]').val(picker.endDate.format());
                form.trigger('change.updateChart');
            }
        "),
        'cancel.daterangepicker' => new JsExpression(/** @lang JavaScript */"
            function (event, picker) {
                var form = $(event.element[0]).closest('form');
                var span = form.find('#{$id}-period-btn span');

                span.text(span.data('prompt'));

                form.find('input[name=from]').val('');
                form.find('input[name=till]').val('');
                form.trigger('change.updateChart');
            }
        "),
    ],
    'clientOptions' => [
        'ranges' => [
            Yii::t('hipanel', 'Current Month') => new JsExpression('[moment().startOf("month"), new Date()]'),
            Yii::t('hipanel', 'Previous Month') => new JsExpression('[moment().subtract(1, "month").startOf("month"), moment().subtract(1, "month").endOf("month")]'),
            Yii::t('hipanel', 'Last 3 months') => new JsExpression('[moment().subtract(3, "month").startOf("month"), new Date()]'),
            Yii::t('hipanel', 'Last year') => new JsExpression('[moment().subtract(1, "year").startOf("year"), new Date()]'),
        ],
    ],
], $this->pickerOptions);
...
?>

As a widget



= DateRangePicker::widget([
    'model' => $search->model,
    'attribute' => 'create_from',
    'attribute2' => 'create_till',
    'options' => [
        'class' => 'form-control',
    ],
    'dateFormat' => 'yyyy-MM-dd',
]) ?>

License

This project is released under the terms of the BSD-3-Clause license. Read more here., (*9)

Copyright © 2018, HiQDev (http://hiqdev.com/), (*10)

Acknowledgments

This package is based on omnilight/yii2-bootstrap-daterangepicker., (*11)

The Versions

18/05 2018

dev-master

9999999-dev https://github.com/hiqdev/yii2-daterangepicker

Date Range Picker widget for Yii2

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

yii2 widget daterangepicker