Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interactive grid dynamic sum in a total row

Ace1Feb 14 2022

I am struggle with a dynamic sum in my IG. I created items which sum up values in columns dynamically but it is not looking too good. When users zoom out the screen, items stretch too much. I tried to fix it with the column span attribute but it didn't work. Is it possible to place items inside the IG? Or maybe add to the IG code union all with values of items and refresh only one row when users change values in the IG?

This post has been answered by Hamza Al-abbasi on Feb 14 2022
Jump to Answer

Comments

Hamza Al-abbasi
Answer

Hello Ace1,
Can you give a screen shot?

Marked as Answer by Ace1 · Feb 15 2022
Ace1

Sure,

image.png

Hamza Al-abbasi

What is the problem with zoom out ?

Ace1

Hamza,
Problem with a zoom out occurred with items but it was just a workaround. I'd like to have the IG with feature like I pasted above on the screenshot

Hamza Al-abbasi

IG Cookbook app have an example like that on my workspace :
Workspace: hamzasoft
Username/Password: demo/demo0000
Application 138659 - Page 5

Ace1

It's not a solution, I need to dynamically sum a column inside the IG, not as an item in another region.

Hamza Al-abbasi

This is not a built-in feature, it needs more JS, in this case it will work if your IG pagination is scroll with aggregate. I have an example on my workspace :
Workspace: hamzasoft
Username/Password: demo/demo0000
Application 62472 - Page 17

Ace1

Hamza, thanks a lot! This is exactly what I needed

John Snyders-Oracle

For newer APEX releases take a look at
JSDoc: Interface: model (0 Bytes)properties aggregates.
For example EMP table SAL column add to JS init code:

function(options) {
    options.defaultGridColumnOptions = {
        aggregates: ["SUM"]
    };
    return options;
}

This is much less code than the old way!

Ace1

@john-snyders-oracle thanks a lot! It's working great but I struggle with one thing, how to round values?
image.png

John Snyders-Oracle

I think all you need to do is give the column a format mask. I tried FML999G999G999G999G990D00. This is the declarative option Format Mask for a number column.
One other note for using aggregates option is that the IG must have a primary key defined.

Ace1

@john-snyders-oracle I tried with FML999G999G999G999G990D00 and it's still the same, I have a number column type and a primary key in my IG.

John Snyders-Oracle

Just give the column a format mask.

Mohamed Sameer

@hamza-alabbasi
Do you have a JS function to get a sum of multiple columns in IG

Hamza Al-abbasi

Hi md-sameer,
Please open a new thread and explain your issue.

User187849

hi ,
I have added the same logic in SUM column properties but I couldn't get the total value

function(options) {
    options.defaultGridColumnOptions = {
        aggregates: ["SUM"]
    };
    return options;
}
Robin Biju

Hi John Snyders-Oracle, can this value assign to any page item?
Thanks.

John Snyders-Oracle

@robin-biju When using model field option aggregates the aggregate value cannot be stored directly in an item. There are ways to data out of a model into an item but it can be trickier for aggregate rows. (Model method getAggregateRecord is not documented and not clear how useful it is.)
If you want to save the aggregate value to a page item you can use the method shown in the IG Cookbook page 5.

1 - 18

Post Details

Added on Feb 14 2022
18 comments
5,969 views