This site is currently read-only as we are migrating to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 30th, when you will be able to use this site as normal.

    Forum Stats

  • 3,889,956 Users
  • 2,269,775 Discussions
  • 7,916,823 Comments

Discussions

Keeping a running total in a page item when checkbox in classic report is checked or unchecked ...

bondurs
bondurs Member Posts: 82 Blue Ribbon

Greetings:

I'm using:

ORACLE APEX Version: 21.2.1

ORACEL DB Version: 19.0.0.0

My question is;

If I have a classic report in ORACLE APEX with a checkbox in the first column, and I want to keep a running total of the Amount column in the report when the checkbox is checked in a display-only page item above the report. I also want to subtract from this running total if a user unchecks the check box. How do I go about accomplishing this?

To word it another way: After the report is queried, the running total in the page item should be zero. As they check the boxes in the first column, the Amount in another column is added to the display-only page item. If the user unchecks the box, it subtracts from the total.

Thanks,

Stan

Best Answer

Answers

  • Hamza Al-abbasi
    Hamza Al-abbasi Mid-level Oracle APEX Developer Member Posts: 873 Bronze Crown
    edited Feb 1, 2022 4:40PM

    Hello bondurs,

    Why you don't use Interactive Grid ?

    There is a useful example in IG Cookbook - Page 5.

  • bondurs
    bondurs Member Posts: 82 Blue Ribbon

    Thanks for the response Hamza. I will take a look at that. I would prefer to use the classic report though, since my users are familiar with that type of report and the way it works regarding sorting and downloading CSV files.

  • Joe Upshaw
    Joe Upshaw Member Posts: 983 Silver Badge

    I will give you my ever unpopular JavaScript approach for doing this, @bondurs. I do not know of another way to do this if you're truly set on using the Classic report.

    You'll need to add 2 classes. So, on the column attributes in the Column Formatting section under CSS Classes... On the checkbox column, add a class of sumCheckBox. On the column containing the amount you want to sum, add a class of sumAmount.

    You will also need to give your Classic Report region a value for Static ID. For this example, we'll name it CLICK_SUMMER_CR.

    We'll assume your Page Item is named: P01_SUMMED_AMOUNT.

    Create a Dynamic Action on Click of the Check Box column using your handy-dandy, newly assigned class.

    Identification
      Name: maintainClickedTotal
    When
      Event: Click
      Selection Type: jQuery Selector
      jQuery Selector: sumCheckBox
    Advanced
      Event Scope: Dynamic
      Static Container (jQuery Selector): #CLICK_SUMMER_CR
    

    Change the action to "Execute JavaScript"

    Use this JavaScript:

    let isChecked = $(this.triggeringElement).prop('checked');
    let amountToAdjustBy = $(this.triggeringElement).closest('tr').find('.sumAmount').html();
    
    if( isChecked == false )
    {
      amountToAdjustBy = (amountToAdjustBy * -1);
    }
    
    let currentlySummedAmount = parseFloat($v('P01_SUMMED_AMOUNT'));
    let newSummedAmount = currentlySummedAmount + amountToAdjustBy;
    
    $s('P01_SUMMED_AMOUNT', newSummedAmount );
    

    Full disclosure, I wrote this off the top of my head. It looks right but, there might be a typo or something in there. At any rate, this should give you the gist of things.

    Cheers,

    -Joe

  • bondurs
    bondurs Member Posts: 82 Blue Ribbon

    Hi Joe,

    Thanks for your response. I took your code and added it to my application, but nothing happens. I put several alerts in the JavaScript code, even one at the very top of the code, and yet none of them execute, so I don't think the dynamic action is firing.

    The only thing I changed in your JavaScript was the item P01_SUMMED_AMOUNT, which was changed to P604_SUMMED_AMOUNT.

    Any suggestions? Thanks so much for your assistance!

    Stan

  • Joe Upshaw
    Joe Upshaw Member Posts: 983 Silver Badge

    @bondurs ,

    The most likely cause is that the class isn't set on your clicked column field. You can right click on one of them and, in the developer tools, check the class attribute. That's the only reason I can think of that it wouldn't fire.

  • bondurs
    bondurs Member Posts: 82 Blue Ribbon

    Hi Joe,

    I checked and re-checked and re-checked my code, but I couldn't find anything that is different in my code compared to yours.

    My checkbox column has the CSS Classes populated with sumCheckBox:

    My Paid Amout (table column was misspelled) has been given a CSS class of sumAmount:

    My Classic Report region has a static ID of CLICK_SUMMER_CR

    My page item name is P604_SUMMED_AMOUNT

    And here is my Dynamic Action:

    Here is the html for the checkbox column:

    And that's how it looks. It never executes the Dynamic Action. Might you see why?

    Thanks for your help on this!

    Stan

  • Joe Upshaw
    Joe Upshaw Member Posts: 983 Silver Badge
    edited Feb 8, 2022 7:10PM

    @bondurs

    Your jQuery selector (my fault!) is missing the preceding period. It should be: .sumCheckBox

    The period is jQuery language for the class attribute, in the same way that # indicates the ID attribute.

    I really think that's the whole issue.

    -Joe

  • bondurs
    bondurs Member Posts: 82 Blue Ribbon
    Answer ✓

    You're the man Joe! That was the issue. Thanks so much for your help!