KoolReport's Forum

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

Inputs DataTime Picker question #1549

Open Richb201 opened this topic on on Aug 2, 2020 - 9 comments

Richb201 commented on Aug 2, 2020

I have a report MyReport.view.php. Near the top I have

echo "<br><br><br><br><br><br><h3>Report for:  ".$_SESSION['campaign']." for tax year ended";
\koolreport\inputs\DateTimePicker::create(array("name" => "dateRange","format"=>"YYYYMM"));

This shows an input field as shown.

But I need a submit button. The rest of the report (in the same tab) will be modified based on the date entered. Do you have an example anywhere of using dateTimePicker with a submit button?

KoolReport commented on Aug 3, 2020

Basically you can do this:

<form method="post">
    <?php DateRangePicker::create(....); ?>
    <button type="submit">Submit</button>
</form>

Basically, we need to create a html form that cover the DateRangePicker. In the form, there is submit type button. So when the button is click, the form will be posted to server with information including the selected date from date range picker.

Hope my explanation helps.

Richb201 commented on Aug 3, 2020
<?php
    echo "<br><br><br><br><br><br><h3>Report for:  ".$_SESSION['campaign']." for tax year ended";
//    \koolreport\inputs\DateTimePicker::create(array("name" => "dateRange","format"=>"YYYYMM"));
?>
<form method="post">
    <?php \koolreport\inputs\DateTimePicker::create(array("name" => "dateRange","format"=>"YYYYMM")); ?>
    <button type="submit">Submit</button>
</form>

The problem is that the form is on the report that has already been rendered. So when a user enters a new date and then presses submit, I need to re-render the entire report, using the new date. I have also noticed that after pressing submit, the input field returns to the default value, instead of the value just entered by the user.

KoolReport commented on Aug 3, 2020

You do like this:

class MyReport extends \koolreport\KoolReport
{

    use \koolreport\inputs\Bindable;
    use \koolreport\inputs\POSTBinding;    

    protected function defaultParamValues()
    {
        return array(
            "dateRange"=>array('2017-07-01')
        );
    }

    protected function bindParamsToInputs()
    {
        return array(
            "dateRange"
        );
    }
    ...
}

I see you use the DateTimePicker but use the name "dateRange", it may cause confusion. It better to name it differently. In my above code, I use the "dateRange" to match with your DateTimePicker.

Richb201 commented on Aug 4, 2020

Thank you. For the default, I would like keep the user's last date used in mySQL and populate the report based on this date. Will this be an issue since the Datastores are created prior to the MyReport.view.php being displayed? Or would it be better to get all the records for a specific user and filter for the current date in the pipe?

Richb201 commented on Aug 4, 2020

I am trying to set the default data from MyReport.php using defaultParamValues(). I'd like to set dateRange=$endDate. I will get endDate from my table. I'd like to set the default in this format YYYYMM. I put a break point in defaultParamValues() and it seems that function is not running. Do I need to call it myself? How about bindParamsToInputs()? Does that need to be called by me too?

KoolReport commented on Aug 7, 2020

The defaultParamValues() is where you can set default value for parameters. The default will set before the setup() function is run so if you need to set default value that base on the data from your database, you need to do this:

function defaultParamValues() {
    $store = $this->src("select min(date) as minDate, max(date) as maxDate from mytable")->pipe(new \koolreport\core\DataStore);
    $store->requestDataSending();
    //Now you have data in the $store which you can access
    $minDate = $store->get(0,"minDate");
    $maxDate = $store->get(0,"maxDate");

    return [
        "dateRange"=>[$minDate,$maxDate]
    ]
}

Above is just my example to show you how to make query to get data from databases inside defaultParamValues(). Hope that helps.

Richb201 commented on Aug 9, 2020

thx

Richb201 commented on Aug 10, 2020

I realize that the setup is running before the report is being displayed, and that I am trying to have the user modify the date from within the report. I was hoping that if the user enters a different date than the default one already on the report, that I will completely re-run setup and set a new default date with their "new" date. BTW, I only have one date. The report will run on the last 12 months from whatever date they set.

The default date is being set to 202008 which is now. The default date that I set below (2017-07) is not being set:

   protected function defaultParamValues()
    {
        return array(
            "dateRange"=>array('2017-07-01')
        );
    }

    protected function bindParamsToInputs()
    {
        return array(
            "dateRange"
        );
    }

This not a problem, other than the date field in the report is always being overwritten, back to 202008.

Richb201 commented on Aug 12, 2020

Is this command documented anywhere in your documentation?

requestDataSending();

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
None yet

None