I am using Apex 18.2. I have a page with an interactive grid with a column "Total" whose sum value should get calculated through looping over the model whenever the sum changes for example, when a new row is created, a row is deleted, a row column's value has changed, etc. I am subscribing to the model to accomplish the task. But there are many model notifications one could listen to. I only need to listen to the model notifications that would affect the sum of the Total column to avoid looping through the model when unnecessary. Could you tell me which notifications are they? https://docs.oracle.com/en/database/oracle/application-express/18.2/aexjs/model.html
Asked
Active
Viewed 398 times
1 Answers
1
The best way to learn about this is to explore. Add the following to your page's Execute when Page Loads attribute:
var model = apex.region('REGION_ID').widget().interactiveGrid("getCurrentView").model;
model.subscribe({
onChange: function(changeType, change) {
console.log(changeType, change);
}
});
Then work with your IG and note the changeType
values logged - those are the notification names that are listed in the doc.
Note that there are rows on the server, rows in the model, and rows displayed in the DOM - the numbers may or may not be different so keep that in mind for aggregate functions that need to work with "all" of the rows.

Dan McGhan
- 4,479
- 1
- 11
- 15
-
I did so, already. But I was concerned that there might be some actions that could cause a notification to fire that I can not think of. I noticed now that the documentation tells about which notification is fired when using a specific method which helped too. Thanks a lot Dan. – Eslam May 09 '20 at 02:46
-
I think I implemented it well but I want to be sure about that because it's something I do not want to get wrong. I'd appreciate if you share your opinion with me about it. I calculate the total's sum only if type is not set, move, metaChange, insert, or clearChanges. I do not think any of them would affect the sum of the total column, right? P.S. I excluded "set" type because there is an on-change DA on total column that calculates the sum of the total too. – Eslam May 11 '20 at 03:14
-
I suppose that's a good list. Though I wonder about exclusionary lists vs. inclusionary. If the point is to avoid unnecessary work, I would go with inclusionary and add new `changeType` values only when necessary (if ever). – Dan McGhan May 12 '20 at 21:00
-
Not sure I get it. But if I, the model has 11 notifications. That's why I excluded the above 5 instead of including the other 6. – Eslam May 13 '20 at 01:05
-
1What I meant was, if 5 new notifications were added in the next release of APEX (unlikely) and only 1 of them affected the sum, then you would be doing unnecessary work for the other 4. If you explicitly list the notifications that matter, then this will not happen. Of course, you'd have to catch the 1 that does matter and add it to your code. Honestly, I think you're fine either way, provided the work is all done in the client. – Dan McGhan May 13 '20 at 16:55