Get datepicker range

Stimulsoft Dashboards.JS discussion
Post Reply
Terravexo
Posts: 3
Joined: Tue Apr 23, 2024 1:12 am

Get datepicker range

Post by Terravexo »

Hello!

First off, apologies if this has been asked elsewhere, I have searched and searched for the past 24 hours and got nowhere.

I have very simple dashboard connecting to a json (in php) script.

Ideally I want to send some parameters to the json URL based on my ranged date picker (called DatePicker1):

Something like: /myjson.php?DateRange=[range]

Now, I believe I can update the data source pragmatically and just re-sync (although if anyone wants to provide code, it would certainly help), but what I am really struggling with is getting the values of DatePicker1 both initially and whenever it's changed by the end user.

I've tried all sorts of permutations of getComponentByName but I am not able to get anything to work.

Is anyone able to help at all with some example JS code?

Many thanks in advance!
Lech Kulikowski
Posts: 6302
Joined: Tue Mar 20, 2018 5:34 am

Re: Get datepicker range

Post by Lech Kulikowski »

Hello,

Please try to use variables (Request From User) for that task:
https://www.stimulsoft.com/en/documenta ... meters.htm

Thank you.
Terravexo
Posts: 3
Joined: Tue Apr 23, 2024 1:12 am

Re: Get datepicker range

Post by Terravexo »

Thanks Lech,

I now have a variable with a date range.

How can I find when that changes with JavaScript and then update the data source to refresh the report?

Thanks again for your help!
Lech Kulikowski
Posts: 6302
Joined: Tue Mar 20, 2018 5:34 am

Re: Get datepicker range

Post by Lech Kulikowski »

Hello,

Please check the onPrepareVariables event:
https://www.stimulsoft.com/en/documenta ... events.htm

Also, you can use these variables directly in the query:
select * from Table where column = {Variable}

Thank you.
Terravexo
Posts: 3
Joined: Tue Apr 23, 2024 1:12 am

Re: Get datepicker range

Post by Terravexo »

Thanks Lech,

It looks like I'm getting there slowly.

I've managed to update the data source (json file), but it looks like this doesn't render on the first attempt. It's almost as if the data source has changed, but does not render that change during onBeginProcessData, and when I call onBeginProcessData a 2nd time, the URL has been changed, therefore the render from the initial call is then displayed.

Can you help? Here's my code.

Code: Select all

        viewer.onBeginProcessData = (args, callback) => {
            if (report.variables.entries.has('variable1')) {
                let variable1 = report.variables.entries.get('variable1');

                let startDate = variable1.value.from.innerDate; // Get the start date
                let endDate = variable1.value.to.innerDate; // Get the end date

                console.log("Start Date:", startDate);
                console.log("End Date:", endDate);

                if (endDate.toISOString().includes("2027")) { // Just an example to test with
                        //alert('2027');
                        dbJSON = report.dictionary.databases.getByName("JSON");
                        dbJSON.pathData = "/demodata.php"; // Dashboard is only re-rendered with this data path after submitting the variable again (2nd run of onBeginProcessData)
                        callback();
                }
            }
        } 

Again, many thanks for your advice!
Lech Kulikowski
Posts: 6302
Joined: Tue Mar 20, 2018 5:34 am

Re: Get datepicker range

Post by Lech Kulikowski »

Hello,

Please send us a sample project that reproduces the issue for analysis.

Thank you.
Post Reply