Yii Framework Forum: Yii2-Date-Range - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii2-Date-Range Advanced date range picker control for Yii 2.0 using Bootstrap 3.x sty Rate Topic: -----

#1 User is offline   Kartik V 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 651
  • Joined: 29-August 12

Posted 10 July 2014 - 12:37 AM

This is the forum for the yii2-date-range extension for Yii framework 2.0.

This extension is a date range picker widget for Yii 2.0 using Bootstrap 3.x styles and preset date selection dropdowns and more.

Refer documentation and/or view a complete demo.
0

#2 User is offline   J_jack_K 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 15-July 14

Posted 15 July 2014 - 08:45 AM

Hi Katik,
I had some problem to set the ranges,

I've tried

$datepicker = DateRangePicker::widget([
    'name'=>'date_range_1',
    'useWithAddon'=>false,
    'language'=>'it',             // from demo config
    'hideInput'=>true,           // from demo config
    'presetDropdown'=>true, // from demo config
    'pluginOptions'=>[
        'format'=>'d/MM/YY',             // from demo config
        'separator'=>' - ',       // from demo config
        'opens'=>'right',
		'ranges' => [
			"Oggi" => ["moment()", "moment()"],
			"Ieri" => ["moment().subtract('days', 1)", "moment().subtract('days', 1)"],
			"Mese Corrente" => ["moment().startOf('month')", "moment().endOf('month')"],
			"Mese Scorso" => ["moment().subtract('month', 1).startOf('month')", "moment().subtract('month', 1).endOf('month')"],
		],
	],
]);


but seems the extension override my setting.

So I had to change the Inizializing pluginOption range list addind one more if before setting $this->pluginOptions['ranges'].

/**
     * Initializes the pluginOptions range list
     */
    protected function initRange()
    {
        if ($this->presetDropdown) {
            $this->initRangeExpr = true;
            if (!isset($this->pluginOptions['ranges'])) // test ranges before set
	            $this->pluginOptions['ranges'] = [
	                Yii::t('kvdrp', "Today") => ["moment()", "moment()"],
	                Yii::t('kvdrp', "Yesterday") => ["moment().subtract('days', 1)", "moment().subtract('days', 1)"],
	                Yii::t('kvdrp', "Last {n} Days", ['n'=>7]) => ["moment().subtract('days', 6)", "moment()"],
	                Yii::t('kvdrp', "Last {n} Days", ['n'=>30]) => ["moment().subtract('days', 29)", "moment()"],
	                Yii::t('kvdrp', "This Month") => ["moment().startOf('month')", "moment().endOf('month')"],
	                Yii::t('kvdrp', "Last Month") => ["moment().subtract('month', 1).startOf('month')", "moment().subtract('month', 1).endOf('month')"],
	            ];
            $this->pluginOptions['startDate'] = new JsExpression("moment().subtract('days', 29)");
            $this->pluginOptions['endDate'] = new JsExpression("moment()");
        }
        if (!$this->initRangeExpr || empty($this->pluginOptions['ranges']) || !is_array($this->pluginOptions['ranges'])) {
            return;
        }
        $range = [];
        foreach ($this->pluginOptions['ranges'] as $key => $value) {
            if (!is_array($value) || empty($value[0]) || empty($value[1])) {
                throw new InvalidConfigException("Invalid settings for pluginOptions['ranges']. Each range value must be a two element array.");
            }
            $range[$key] = [static::parseJsExpr($value[0]), static::parseJsExpr($value[1])];
        }
        $this->pluginOptions['ranges'] = $range;
    }


There was some othe way?

One more question. How can I setup to have immediatly both rangelist and the two caledar as in the bootstrap example?
0

#3 User is offline   Kartik V 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 651
  • Joined: 29-August 12

Posted 16 July 2014 - 02:29 AM

@J_jack_K if you want to configure your own ranges list, then set presetDropdown to false and then set your ranges. If presetDropdown is set to true, plugin will use the preset defaults inside.

But, if you want to use the presetDropdown as is, and just change the language, submit a translation using these instructions.

When using a rangeList, clicking the Custom Range option will show the DOUBLE CALENDAR.

You can read the documentation here or view a demo.
0

#4 User is offline   J_jack_K 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 15-July 14

Posted 16 July 2014 - 06:35 AM

Hi Kartik,
yes presetDropdown to false works fine.

About

View PostKartik V, on 16 July 2014 - 02:29 AM, said:

When using a rangeList, clicking the Custom Range option will show the DOUBLE CALENDAR.


I know that Custom Range show the double calendare but I wolud like to have the double calenrad immediatly without click the custom range.

Thank's
Jack
0

#5 User is offline   Kartik V 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 651
  • Joined: 29-August 12

Posted 16 July 2014 - 12:18 PM

View PostJ_jack_K, on 16 July 2014 - 06:35 AM, said:

Hi Kartik,
yes presetDropdown to false works fine.

I know that Custom Range show the double calendare but I wolud like to have the double calenrad immediatly without click the custom range.


That's how the plugin is defined by default. You can read and check details here. The reason probably is that selections of presets in the ranges, will automatically select a calendar range (so showing a calendar will not help in that case because its a preselected range).

However, in a custom range, you actually need to pick dates from the calendar. You can probably raise an enhancement request if needed with the plugin owner to see if it can be included.
0

#6 User is offline   D1mond 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 05-September 14

Posted 05 September 2014 - 03:59 AM

Hi Kartik!

I installed the "kartik-v/yii2-date-range": "dev-master", but i've exception - Getting unknown property: kartik\daterange\DateRangePicker::language. Help please!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users