Skip to main content

Updateable Interactive Report - Websheets style

For a current project the customer needed an Interactive Report with update functionality - in an Excel like style. Since we couldn't wait for APEX 4.0, we decided to build it in the current version.
The requirement is that the user can change some fields in the report (the Expenses, budget and estimates) for every year of the project life cycle and then the funding should be calculated according a defined formula (to financially smooth things out).
So I created a nice view with a formula to show the budget en estimate and the calculate the funding and created an Interactive Report on top of it.
The editable fields are created using the apex_item.text function with the p_attributes parameter set to:
'onclick=editField(<type>,<key1>,<key2>) readonly class="editField"'.
Once the user clicks on the field, the field is presented in a different style, made editable and with two little icons next to it.
After making the change, the user hits the green tick and an Application Process is fired to update the value in the database - and the report is requeried (showing the updated amounts for the fundings). If he hits the little red cross the edit is canceled; the same happens when he clicks another field.

You can see the result here. You can edit the blueish fields and, once you hit the green tick, the fundings for that year are automagically recalculated. I guess even Websheets doesn't do that...
If you are interested in the details of the code, just take a look at the source of the HTML-page!

Comments

Mark Lancaster said…
Nice one Roel.

Just one question, how are you handling stale records?

While, the chances are low that someone else is modifying the record, I think you still need to pass a checksum and compare.

Of course this complicates things, as you then need to handle the error message etc, when the record has been modified.

Regards

Mark
Tobias Arnhold said…
Hey Roel,

nice solution. Thanks for sharing your idea.

Best regards,

Tobias
Roel said…
Mark,
Stale records aren't an issue in mu case, because only a projectmanager can edit the figures for his own project. In other cases you either need to add a checksum or add the original value and check that when updating the value in the App Process.
Roel
dmcghan said…
Roel,

Getting caught up with blog reading... Great post. I had wanted to do this for a while but hadn't found the time. Very nice!

Regards,
Dan
Stew said…
Roel,

Very cool stuff, as usual!

At first it seemed very slow to refresh, but was instantaneous this last time. I was surprised that the Estimate value didn't change (e.g. $400k for the first group, Code 10), but the calculation must be updating some other figure?

This does not look like an Interactive Report to me at all, except for clicking on the Year column header. Even there, I was surprised there was no Accept/Cancel buttons, but that's probably because it's a demo and the images aren't available? I think you've done a fantastic job making this look like a custom report. Making a column editable is just over-the-top incredible.

I'm very surprised you can use apex_item.text to perform these updates. I'm a bit unclear what the onclick action is doing. Is it calling a jquery function? I only ask because I see you use jquery elsewhere.

Thanks,

Stew
Roel said…
@Stew,
Thanks for the compliments. Glad you liked it. If you change one of the "blue fields" the figures below change (code 70,71,99) according to some kind of calculation rule.
If you change a value and it the green "ok" image an application process is fired to commit the changes and refreshes the report.
jQuery is used to show the images and (re)set the css used.
Anonymous said…
Hi Joel, Please check the link, that page is not working now.

Can you please tell me how u are updating the database by clicking the check mark.

And what are those parameters ,,

thanks
Tauceef
Hi joel,
Nice post, I was looking for this solution for my application, it is great.

Can you please check the link, its not working now, its showing some error.

And also can you please explain me the function editField() and how can I use this process in my application.

Thanks
Tauceef
Roel said…
To me the link is working (now). Might have been a problem at apex.oracle.com.

The rest of the javascript code is:

<script language="JavaScript" type="text/javascript">

function editField( pType, pBeg, pJaar ) {
removeEdit();
elem = document.getElementById( pType+pBeg+"-"+pJaar );
$( elem ).attr( "readonly", false ).addClass( "Edit" );
BorV = pType;
$( '<img id="savebut" src="/i/Fndokay1.gif" height="12px" onclick="save('+pBeg+','+pJaar+')"/><img id="cancelbut" src="/i/FNDCANCE.gif" height="12px" onclick="cancel()"/>').insertAfter( elem );
}

function removeEdit(){
$( ".Edit" ).attr( "readonly", true ).removeClass( "Edit" );
$( "#savebut" ).remove();
$( "#cancelbut" ).remove();
}

function save( pBeg, pJaar){
pType = BorV;
elem = document.getElementById( pType+pBeg+"-"+pJaar );
val = elem.value;
var lRequest = new apex.ajax.ondemand('saveBudget',
function(){
/* start the return function */
var l_s = p.readyState;
if(l_s == 1||l_s == 2||l_s == 3){
}else if(l_s == 4){
gReturn = p.responseText;
if(gReturn){ alert(gReturn); }
else{
gReport.search('SEARCH');
}
}else{return false;}
/* end the return function */
}
);
lRequest.ajax.addParam('x01',val);
lRequest.ajax.addParam('x02',pBeg);
lRequest.ajax.addParam('x03',pJaar);
lRequest.ajax.addParam('x04',pType);
lRequest._get();
removeEdit();
}

function cancel(){
removeEdit();
}

</script>

HTH
Roel
Thanks for reply Roel

Sorry, but it is still giving me an error saying:
"Error ERR-1412 Unable to resolve page alias (PROJECTSHEET)"

See the link which I am getting when I am clicking on that link, may be help you out to find the problem:
"http://apex.oracle.com/pls/otn/f?p=ROEL:PROJECTSHEET:::::P5_NUM_PPRJ:1"

but I am still not able to get How you are updating the data in the database with the values user had changed, is that you are doing in the save function? or I have to create a sql process for that? if yes how I am going to call that process from the javascript?

Thanks Again.
Roel said…
Strange, the link is working fine for me. But you can replace PROJECTSHEET with 5 (as that's an alias for Page 5).
Regarding the update:
Tha javascript save function uses an ajax call to an Application Process: apex.ajax.ondemand('saveBudget', ...

This "saveBudget" is a (PL/SQL) On Demand Application Process that's using the parameters : lRequest.ajax.addParam('x01',val);
lRequest.ajax.addParam('x02',pBeg);
lRequest.ajax.addParam('x03',pJaar);
lRequest.ajax.addParam('x04',pType);

In the Applicationn Process itself the parameters are passed using:
p_val := to_number(wwv_flow.g_x01);
p_beg := to_number(wwv_flow.g_x02);
p_jaar := to_number(wwv_flow.g_x03);
p_type := wwv_flow.g_x04;
These variables are used for a regular update statement.

Hopes this makes it all clear(er).
Hi Roel,

Sorry to disturb you again and again, actually I am new to ajax and Jquery, still I am phasing problem understanding the functions, parameters and their working, can I have access to your workspace(or a demo application) to see how you have written these functions, so that I get a clear Idea of how can I do this.

Thanks
Hi Roel,
with the help of your code I have done the designing part, everything is working correctly except when I click on green tick mark, a javascript error is there saying gReport is undefined.

This is my application process:
declare
val varchar2(30);
id varchar2(5);
pType varchar2(5);
eno number;
begin
val := wwv_flow.g_x01;
pType := wwv_flow.g_x02;
id := wwv_flow.g_x03;
eno := to_number(wwv_flow.g_x04);
if id = 'f_31' then
update emp set ename = val where empno = eno;
end if;
end;

and here is my javascript:

function save(eno){
//alert('hi');
elem = document.getElementById(F29420_PID + F29420_PITEM);
//alert(elem.value);
val = elem.value;
//alert(val);
var lRequest = new apex.ajax.ondemand('saveBudget',
function(){
/* start the return function */
var l_s = p.readyState;
if(l_s == 1||l_s == 2||l_s == 3){
}else if(l_s == 4){
gReturn = p.responseText;
if(gReturn){ alert(gReturn); }
else{
gReport.search('SEARCH');
}
}else{return false;}
/* end the return function */
}
);
lRequest.ajax.addParam('x01',val);
lRequest.ajax.addParam('x02',F29420_PITEM);
lRequest.ajax.addParam('x03',F29420_PID);
lRequest.ajax.addParam('x04',eno);
lRequest._get();
removeEdit();
}

right now I am just updating one column after this, I will work on the whole report.

Please have a look on it and tell me what is the problem.
If you want you can see the link:
http://apex.oracle.com/pls/apex/f?p=29420:12::::::

Thanks
Tauceef

Popular posts from this blog

Refresh selected row(s) in an Interactive Grid

In my previous post I blogged about pushing changed rows from the dabatase into an Interactive Grid. The use case I'll cover right here is probably more common - and therefore more useful!

Until we had the IG, we showed the data in a report (Interactive or Classic). Changes to the data where made by popping up a form page, making changes, saving and refreshing the report upon closing the dialog. Or by clicking an icon / button / link in your report that makes some changes to the data (like changing a status) and ... refresh the report.  That all works fine, but the downsides are: The whole dataset is returned from the server to the client - again and again. And if your pagination size is large, that does lead to more and more network traffic, more interpretation by the browser and more waiting time for the end user.The "current record" might be out of focus after the refresh, especially by larger pagination sizes, as the first rows will be shown. Or (even worse) while you…

Dockerize your APEX development environment

Nowadays Docker is everywhere. It is one of the main components of Continuous Integration / Continuous Development environments. That alone indicates Docker has to be seen more as a Software Delivery Platform than as a replacement of a virtual machine.

However ...

If you are running an Oracle database using Docker on your local machine to develop some APEX application, you will probably not move that container is a whole to test and production environments. Because in that case you would not only deliver a new APEX application to the production environment - which is a good thing - but also overwrite the data in production with the data from your development environment. And that won't make your users very excited.
So in this set up you will be using Docker as a replacement of a Virtual Machine and not as a Delivery Platform.
And that's exactly the way Martin is using it as he described in this recent blog post. It is an ideal way to get up and running with an Oracle database …

apex_application.g_f0x array processing in Oracle 12

If you created your own "updatable reports" or your custom version of tabular forms in Oracle Application Express, you'll end up with a query that looks similar to this one:
then you disable the "Escape special characters" property and the result is an updatable multirecord form.
That was easy, right? But now we need to process the changes in the Ename column when the form is submitted, but only if the checkbox is checked. All the columns are submitted as separated arrays, named apex_application.g_f0x - where the "x" is the value of the "p_idx" parameter you specified in the apex_item calls. So we have apex_application.g_f01, g_f02 and g_f03. But then you discover APEX has the oddity that the "checkbox" array only contains values for the checked rows. Thus if you just check "Jones", the length of g_f02 is 1 and it contains only the empno of Jones - while the other two arrays will contain all (14) rows. So for processing y…