APEX
Friday, 20. October 2023., 09:00
Hall C
45'
The interactive grid (IG) is perhaps the most complicated component of Oracle Apex. This is because the IG offers much more than just viewing and editing data. But how does it work? What happens if we insert 'n' rows with some numerical values and want to calculate the current sum of that column before hitting that save button? The problem is that we don't have the newly inserted and updated rows on the server side (inside the database). So we can't simply loop over the data in our database because the data just isn't there. Can't we just loop over those numbers on the client side in JavaScript? Sometimes, but chances are, when working with a large dataset, our IG only has a portion of the dataset loaded in our model. This is done for performance reasons, as working with a large dataset and loading it all into the IG model would require a lot of data transfer and could be time-consuming just for editing and saving a few rows. So we have some data on the server and some on the client. Can we calculate the sum of our column from that? Sure we can.The formula is quite simple, to be honest. It is the sum of (nvl(row-on-client, row-on-server)). And we will do it all in just one language, PL/SQL! But wait, you said that there is no unsaved data in our database! That's where JSON comes into play. We can pack our client-side data into JSON and simply send it to the Ajax callback. There, we can loop through our JSON and get the result from the data on the client side. Then, we can loop through the rest of the data on our server that we haven't touched using sys_refcursor (and we have that on our server).The next real-time problem I had was that most of my colleagues are not JavaScript developers. Packing data in JSON and sending it to the callback is not so simple for them. That's why I have prepared a global workspace JavaScript function for them, which automatically subscribes to the model and sends data to the Ajax callback using just a few lines of code in the JavaScript initialization code. Additionally, I have prepared a universal package in PL/SQL that handles incoming JSON data, sums it up, and does the same for the data on our server. It returns a resolved promise to JavaScript, and there we have our sum. So, fetchAll is not the only option for us anymore!
The conference is organized by the Croatian Association of Oracle users. More about the association can be found at Hroug.hr.