KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

DateRangePicker - Options Array #616

Closed Jonathan Long opened this topic on on Jan 25, 2019 - 2 comments

Jonathan Long commented on Jan 25, 2019

I am having some issues with the Options array for the DateRangePicker package.

My ideal drop down menu would give the user a list of 3 or 4 ranges, with no custom input options. The range would default to either the last 7 days, or last 30 days (Not sure which one yet). I think all the issues are related some how, just not exactly sure.

The first thing I've noticed is that if I don't have the range "today" shown, the calendar shows up regardless of the showCustomRangeLabel option. After reading a little more, I realized that if the text field range does not match a pre-defined range, the text field will show up (so adding Today fixes that issue)

So, now I am trying to set the startDate and endDate using the option array, so that it matches one of the ranges and it won't set the range, and only defaults too today. Reading the date range picker website, it says that if I specify a startDate, it needs to match the locale settings, which appears it does - but I am still not getting any results.

	<?php
		$dateFormat = "m/d/Y";
		$defaultEndDate = date($dateFormat);
		$defaultStartDate = date($dateFormat, strtotime("-1 months"));
		DateRangePicker::create(array(
		"name"=>"dateRange",
		"locale"=>"MM/DD/YYYY",
		"ranges" =>array(
			"Today"=>DateRangePicker::today(),
	        "Last 7 days"=>DateRangePicker::last7days(),
	        "Last 30 days"=>DateRangePicker::last30days(),
	        "This month"=>DateRangePicker::thisMonth(),
	        "Last month"=>DateRangePicker::lastMonth()
	    	),
		"options"=>array(
			"showCustomRangeLabel"=>false,
			"startDate"=>$defaultStartDate,
			"endDate"=>$defaultEndDate),
		)
	);
	?>

I read further about using the defaultParamValues() function, so I tried this:

Completed.php:

    protected function defaultParamValues()
    {
        return array(
        #"dateRange"=>array(date("M jS Y", strtotime("-30 days")), date("M jS Y")),
       "dateRange"=>array('2018-12-25', '2019-01-24')
        );
    }


Completed.view.php
    <?php
		DateRangePicker::create(array(
		"name"=>"dateRange",
		"ranges" =>array(
			"Today"=>DateRangePicker::today(),
	        "Last 7 days"=>DateRangePicker::last7days(),
	        "Last 30 days"=>DateRangePicker::last30days(),
	        "This month"=>DateRangePicker::thisMonth(),
	        "Last month"=>DateRangePicker::lastMonth()
	    	),
		)
	);
	?>

I am still drawing a blank ... and I'm not exactly sure how to make this work?

Suggestions?

KoolReport commented on Jan 26, 2019

It could be the param has not been bound to the input yet, there is method bindParamsToInputs() that needed to implement. Please have a look at this documentation of bindParamToInputs method

Jonathan Long commented on Feb 4, 2019

Hello,

Thank you for your reply. The support pages on these functions aren't well documented and could use a little more clarification - specifically that you need to include both bindParamsToInputs() and defaultParamValues().

In addition, under the defaultParamValues section, there isn't much information about what the array key and value are, so that complicates the understanding of how the function is implemented.

But, after reading this a little further and making some guesses, I was able to figure out how to make this work.

Thank you again for your help

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
solved

None