Limit Date Range

(6 posts) (2 voices)

Tags:

No tags yet.

  1. Dev, Member

    Hi,

    I am using the default date picker, but I want to limit the date picker to only show 'This Month' and 'Last Month' options and hide the rest. How can I achieve this?

    I have tried the following script that was discussed in another forum, but it did not work:

    <script type="text/javascript">
    $(document).ready(function() {
    // Define custom date ranges
    var customRanges = {
    'This Month': [moment().startOf('month'), moment().endOf('month')],
    'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
    };

    // Apply the custom ranges to the date picker
    $('#u3').daterangepicker({
    ranges: customRanges,
    locale: {
    format: 'YYYY-MM-DD'
    }
    });
    });
    </script>

    Can you please assist with this issue? Thank you!

  2. myDBR Team, Key Master

    What is it that you are trying to limit? The select element next to the date range whowing the shortcuts or a date picker calenadar choises?

    Easiest way is the check the chosen date ranges in the report itself.
    --
    myDBR Team

  3. Dev, Member

    I am trying to show only 'This Month' and 'Last Month' in the date range calendar choices.

  4. myDBR Team, Key Master

    If you run the updater, you can use:

    const select = document.querySelector(".param_daterange");
    Array.from(select.options).forEach(option => {
    if (!["none", "thismonth", "lastmonth"].includes(option.getAttribute("data-v"))) {
    option.remove();
    }
    });

    --
    myDBR Team

  5. Dev, Member

    If we are already running the updated version, where should we paste the query? Also, I am not trying to limit the date range for all the reports; I am just looking to limit the date range for an individual report.

  6. myDBR Team, Key Master

    Add the code to report's Help/JavaScript field. Encode it with script-tags. Note that this will not limit the date range, it removes the other options than 'This Month' and 'Last Month' from the shortcut ranges. You can check the ranges in the report.

    --
    myDBR Team


Reply

You must log in to post.