Disable Prev/Next Buttons in Report

telco-schilling
edited February 11, 2022 in Analytics #1
<p>I have a chart report that shows data for a month aggregated by day.  I have added to the grid buttons for Prev-Month and Next-Month. These are HTML Dynamic Text fields. Everything is working  great after implementing many helpful tip and snippets from this forum.</p>
<p> </p>
<p>What I'm looking to do is disable the Next-Month button when the chart is displaying the current month and disable the Prev-Month button is displaying previous month X.</p>
<p> </p>
<p>I know the button can be disable with document.getElementById("my_next_button").disable = true.  I can put this in an if statement to trigger with my hidden report parameter is at the desired month. My problem is I haven't figured out where to put the script performing the IF and DISABLE steps and does this need to be enclosed in <script> tags.</p>
<p> </p>
<p>thanks,</p>
<p>Paul</p>

Comments

  • <p>Hi Paul,</p>
    <p> </p>
    <p>I'm not sure without seeing your report, but it sounds like you already have scripting in the buttons that runs for each button's onClick event to do the "next" and "previous" functionality.  If so, just put the code to enable and disable the buttons inside the same script.</p>
    <p> </p>
    <p>Regards,</p>
    <p>Jeff</p>
    Warning No formatter is installed for the format ipb
  • <p>Hi Jeff,</p>
    <p>I did try that. It disables the button and then re-renders the page for the different month. When page is redrawn the button is again enabled.  I tried afterfactory, afterrender and several other places without success.  Basically it should occur at document.ready but I don't know how that is done in BIRT.</p>
    <p> </p>
    <p>Paul</p>
  • <p>Hi Paul,</p>
    <p> </p>
    <p>That makes sense.  The page is reloading and losing the button setting.  </p>
    <p> </p>
    <p>If you select the report itself, the last event handler is called "clientScripts".  Selecting clientScripts enables the second dropdown which contains two events for client code: "initialize" and "onContentUpdate".  Most likely you code needs to go in onContentUpdate which will trigger each time the window contents change.  You don't need to include the <script> tags inside the event. You can reference DOM objects like "window" in the event.  </p>
    <p> </p>
    <p>I haven't tested this.  If you are able to post an example with buttons that I can run, I'll try to get the enable/disable working. </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <p>Regards,</p>
    <p>Jeff</p>
    Warning No formatter is installed for the format ipb
  • <p>Hi Jeff,</p>
    <p>I guess I should have provided information on the BIRT version I am using.  I use OS BIRT Report Designer 4.6.0. I use both the birt-rpc-report-designer for windows and the birt-report-framework for Eclipse Neon running on Fedora 25.</p>
    <p> </p>
    <p>I looked in clientScripts and I only see one event, initialize.  The dropdown does not have an "onContentUpdate" event.</p>
    <p> </p>
    <p>I will try to create a simplified report with Prev and Next buttons in the next day or two. </p>
    <p> </p>
    <p>Regards,</p>
    <p>Paul</p>
  • <p>I have created a sample report using the sample database.  Created with OS BIRT 4.6.0. Since I was using MySQL and the sample database is using Apache Derby I had to learn how Derby adjusts timestamps. In MySQL I could adjust with 'INTERVAL x MONTH' where x was the current value of hidden report parameter mOffset. With Derby I learnd to use 'timestampadd' as you can see in the data set's beforeOpen script.</p>
    <p> </p>
    <p>For this sample report consider the current month to be April 2013.  When that month is displayed mOffset = 1. When mOffset = 1 the next 'Next Month' button should be disabled.</p>
    <p> </p>
    <p>You will see the Next Month button disable briefly when you click either button as I put the document.getElementById('button_name').disable=true in the onclick event.</p>
    <p> </p>
    <p>Please let me know if you figure out where to put the code to disable the button.</p>
    <p> </p>
    <p>Thanks,</p>
    <p>Paul</p>
    <p> </p>
    <p> </p>
  • <p>Hi Paul,</p>
    <p> </p>
    <p>That's great that you were able to get the example working!  I have not had time to create my own example.  One option that I believe will work is to add the following code to the text element (ID 59):</p>
    <p> </p>
    <div>(function() {</div>
    <div>// insert code here</div>
    <div>})();</div>
    <div> </div>
    <div>The code inside the function will run when a page loads. You have code to get the moffset value.  Add an "if" statement to check the value of moffset and disable the button using standard syntax when the criterion is met for moffset.   I believe you can tell from moffset whether or not to disable the buttons. I'm sorry I haven't had more time to look at your code and create an example.</div>
    <div> </div>
    <div>Regards,</div>
    <div>Jeff</div>
    Warning No formatter is installed for the format ipb
  • <p>Hi Jeff,</p>
    <p>I tried your suggestion and added the function to text element  (ID59) along with the nextData function used by onClick.  I kept it simple and just tried to disable the next button.  Here is the HTML text in this text element:</p>
    <p> </p>
    <p><script><br>
    function nextData(a) {<br>
        var $ = document;<br>
        var cl = new String(location.href);<br>
        var tst = cl.indexOf("&mOffset");<br>
        var topNext = $.getElementById("topNext");<br><br><br>
        if (tst === -1) {<br>
            cl = cl + "&mOffset=" + a + "&__overwrite=true&__parameterpage=false&__designer=false";<br>
            topNext.disabled = true;<br>
        } else {<br>
            var ch = cl.indexOf("&mOffset=");<br>
            cl = cl.substring(0, ch) + "&mOffset=" + a + "&__overwrite=true&__parameterpage=false&__designer=false";<br>
            topNext.disabled = true;<br>
        }<br><br>
    window.location = cl;<br>
    }<br><br>
    (function () {<br>
    document.getElementById("topNext").disable = true;<br>
    })();<br><br>
    </script><br>
     </p>
    <p>If working the way you expected this should have disabled the next month button every time the page loads. It did not work.</p>
    <p> </p>
    <p>Thank you for you efforts. Hopefully you or someone else in the forum can find the solution.</p>
    <p> </p>
    <p>regards,</p>
    <p>Paul</p>
  • <p>Here is my test code.  I added an alert to show when the disable code is triggered.  When I run this, the "Next Month" button is always disabled.  I can click to the previous month or refresh the page and it remains disabled.</p>
    <p> </p>
    <div><script></div>
    <div> </div>
    <div>(function() {</div>
    <div>   alert("test");</div>
    <div>   document.getElementById("topNext").disabled = true;</div>
    <div>})();</div>
    <div> </div>
    <div> </div>
    <div>function nextData( a ){</div>
    <div>var $ = document;</div>
    <div>var cl = new String(location.href);</div>
    <div>var targetURL = new String();</div>
    <div>var tst = cl.indexOf("&mOffset");</div>
    <div>var topNext = $.getElementById("topNext")</div>
    <div> </div>
    <div>if(  tst == -1 ){</div>
    <div> cl = cl + "&mOffset=" + a + "&__overwrite=true&__parameterpage=false&__designer=false";</div>
    <div>}else{</div>
    <div> var ch = cl.indexOf("&mOffset=");</div>
    <div> cl = cl.substring(0, ch) + "&mOffset=" + a + "&__overwrite=true&__parameterpage=false&__designer=false"; </div>
    <div>}</div>
    <div> </div>
    <div>window.location = cl;</div>
    <div> </div>
    <div>}</div>
    <div> </div>
    <div></script></div>
    Warning No formatter is installed for the format ipb
  • <p>Hi Jeff,</p>
    <p>it was a stupid error in my code. I had the method on the button as 'disable' when it should have been 'disabled'.</p>
    <p> </p>
    <p>I have cleaned up the report and have attached the working version for anyone who wants to see how this was implemented.</p>
    <p> </p>
    <p>I greatly appreciate you help.</p>
    <p> </p>
    <p>regards,</p>
    <p>Paul</p>
  • <p>Hi Paul,</p>
    <p> </p>
    <p>That's an easy one to miss.  I looked at the code you posted and didn't notice the "disable".  I'm glad it's working now.  Thanks for posting the working example.</p>
    <p> </p>
    <p>Regards,</p>
    <p>Jeff </p>
    Warning No formatter is installed for the format ipb