yii2-bootstrap-daterangepicker This extension is a wrapper for Bootstrap Datepicker for Yii 2 Framework.

  1. Requirements
  2. Usage
  3. Installation
  4. Resources

Requirements

This extension requires Yii 2 Framework and Yii 2 Bootstrap extension.

Usage

// Include namespace
    use bburim\daterangepicker\DateRangePicker as DateRangePicker;

    // Define  ranges correctly
    $ranges = new \yii\web\JsExpression("{
    					'Today'        : [Date.today(), Date.today()],
    					'Yesterday'    : [Date.today().add({ days: -1 }), Date.today().add({ days: -1 })],
    					'Last 7 Days'  : [Date.today().add({ days: -6 }), Date.today()],
    					'Last 30 Days' : [Date.today().add({ days: -29 }), Date.today()],
    					'This Month'   : [Date.today().moveToFirstDayOfMonth(), Date.today().moveToLastDayOfMonth()],
    					'This Year'    : [Date.today().moveToMonth(0,-1).moveToFirstDayOfMonth(), Date.today()],
    					'Last Month'   : [Date.today().moveToFirstDayOfMonth().add({ months: -1 }), Date.today().moveToFirstDayOfMonth().add({ days: -1 })]
    				}");

    // Define empty callback fust for fun
    $callback = new \yii\web\JsExpression("function(){}");

    // Provide required parameters and render the widget
	  echo DateRangePicker::widget([
			'callback' => $callback,
			'options'  => [
			   'ranges' => $ranges,
			   'locale' => [
			    'firstDay' => 1
			   ]
			],
			'htmlOptions' => [
		    'name'        => 'daterange',
		    'class'       => 'form-control',
		    'placeholder' => 'Select Date Range',
		    'style'       => 'width:190px;',
			]
		]);

Installation

Via Composer:

php composer.phar require "bburim/daterangepicker"

Or download and install manually: https://github.com/bburim/daterangepicker/archive/master.zip

Resources

Github: https://github.com/bburim/daterangepicker

Composer Package: https://packagist.org/packages/bburim/daterangepicker

2 0
5 followers
0 downloads
Yii Version: Unknown
License: GPL-2.0
Category: User Interface
Developed by: ASAP
Created on: Feb 14, 2014
Last updated: 4 years ago

Related Extensions