This document discusses two ways to dynamically sum values in an interactive grid column in Oracle APEX and display the total in a page item. The first method uses JavaScript code to loop through the grid records and calculate the running total, updating the page item. The second method uses dynamic actions to execute JavaScript on cell changes to recalculate the total.
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
2 ways to get total sum of interactive grid column oracle apex ontoor blogs
1. 9/25/21, 5:15 PM 2 ways to get total sum of Interactive Grid Column Oracle APEX - Ontoor Blogs
https://blogs.ontoorsolutions.com/post/2_ways_to_dynamicly_sum_grid_column/ 1/9
Home / Posts / 2 ways to get total sum of Interactive Grid Column Oracle APEX
2 ways to get total sum of Interactive Grid
Column Oracle APEX
Vikas Pandey Feb 6, 2021
2 min read
Vikas Pandey APEX APEX
PLSQL SQL
How to Calculate total sum of interactive grid column into
page item in oracle APEX.
Most of the time, this question was asked by my friends and colleagues that “How to
Calculate total sum of interactive grid column into page item in oracle APEX” then i got
solution in two ways.
Solution 1.
Ontoor Blogs
2. 9/25/21, 5:15 PM 2 ways to get total sum of Interactive Grid Column Oracle APEX - Ontoor Blogs
https://blogs.ontoorsolutions.com/post/2_ways_to_dynamicly_sum_grid_column/ 2/9
1. Need to create an editable interactive grid report using emp table and Page item
Px_ITEM.
2. Copy and Paste below code in “Function and Global Variable Declaration”.
(function($) {
function update(model) {
var salKey = model.getFieldKey("SAL"),
total = 0;
console.log(">> starting sum SAL column")
model.forEach(function(record, index, id) {
var sal = parseFloat(record[salKey]),
meta = model.getRecordMetadata(id);
if (!isNaN(sal) && !meta.deleted && !meta.agg) {
total += sal;
}
});
console.log(">> setting sum SAL column to " + total)
$s("P23_TOTAL", total);
}
$(function() {
$("#emp").on("interactivegridviewmodelcreate", function(event, ui) {
var sid,
model = ui.model;
if ( ui.viewId === "grid" ) {
sid = model.subscribe( {
Ontoor Blogs
3. 9/25/21, 5:15 PM 2 ways to get total sum of Interactive Grid Column Oracle APEX - Ontoor Blogs
https://blogs.ontoorsolutions.com/post/2_ways_to_dynamicly_sum_grid_column/ 3/9
Note: Defile region static id- “emp”.
Solution 2:
1. Now create a dynamic action on the SAL column of IG for change event.
onChange: function(type, change) {
console.log(">> model changed ", type, change);
if ( type === "set" ) {
if (change.field === "SAL" ) {
update( model );
}
} else if (type !== "move" && type !== "metaChange") {
update( model );
}
},
progressView: $("#P23_TOTAL")
} );
update( model );
model.fetchAll(function() {});
}
});
});
})(apex.jQuery);
Ontoor Blogs
4. 9/25/21, 5:15 PM 2 ways to get total sum of Interactive Grid Column Oracle APEX - Ontoor Blogs
https://blogs.ontoorsolutions.com/post/2_ways_to_dynamicly_sum_grid_column/ 4/9
2. Create a true action as Set Value. Set the type PL/SQL expression as :SAL and submit
the SAL.
3. Create another true action to execute JavaScript code and add the following code:
var model = apex.region("ONTOOR").widget().interactiveGrid("getViews", "grid").mo
var n_amt, n_totamt = 0;
col_amt = model.getFieldKey("SAL");
model.forEach(function(igrow) {
n_amt = parseInt(igrow[col_amt], 10);
if (!isNaN(n_amt)) {
n_totamt += n_amt;
}
});
apex.item("P23_TOTAL").setValue(n_totamt);
Ontoor Blogs
5. 9/25/21, 5:15 PM 2 ways to get total sum of Interactive Grid Column Oracle APEX - Ontoor Blogs
https://blogs.ontoorsolutions.com/post/2_ways_to_dynamicly_sum_grid_column/ 5/9
We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.
Demo
You might Like :
3 Ways to Open Inline Model Dialog Using JQuery In Oracle APEX
How to Create Dynamic Navigation Menu in Oracle APEX
Preserve Checkbox state while Paginating in Interactive/Classic Report Oracle APEX
<
Add Tooltip on Side Navigation Menu Oracle
APEX
>
APEX Camera Extension (ACE)
Related Posts
Refresh region of base page when closing modal dialog | Oracle APEX
3 Ways to Unselect Default Checkbox in Interactive Grid Oracle APEX
APEX page types | Universal Theme
Smooth row view Interactive report Oracle APEX
Handle trigger Mutating Error
0 Comments
- powered by
utteranc.es
Write Preview
Ontoor Blogs
6. 9/25/21, 5:15 PM 2 ways to get total sum of Interactive Grid Column Oracle APEX - Ontoor Blogs
https://blogs.ontoorsolutions.com/post/2_ways_to_dynamicly_sum_grid_column/ 6/9
Vikas Pandey
APEX,PLSQL
Ontoor
India
About
Featured Posts
APEX_JSON.WRITE_RAW
First Day of the YEAR : ROUND (DATE)
Download files in APEX
Generate DDL of any object in ORACLE
Styling with Markdown is supported
Sign in to comment
Sign in with GitHub
Ontoor Blogs
7. 9/25/21, 5:15 PM 2 ways to get total sum of Interactive Grid Column Oracle APEX - Ontoor Blogs
https://blogs.ontoorsolutions.com/post/2_ways_to_dynamicly_sum_grid_column/ 7/9
Upload Multiple Files in Oracle APEX
Recent Posts
APEX_JSON.WRITE_RAW
First Day of the YEAR : ROUND (DATE)
Download files in APEX
Generate DDL of any object in ORACLE
Upload Multiple Files in Oracle APEX
How to upload multiple files in APEX
ORACLE INVISIBLE Column can be used for column ordering
How to find ORACLE locked Objects?
APEX APIs
Oracle Application Express JavaScript API Reference
Article publishers
Ashish Sahay Vikas Pandey Hugo Authors Anuj Kumar
Categories
APEX ORACLE PLSQL PLUGINS DBA JavaScript
GitHub SQL BLOGGER ORDS APEX_JSON CSS
SCRUM
APEX Plugins
121 53 6 1
109 27 15 10 6 5
4 4 3 3 2 1
1
Ontoor Blogs