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
Dan McGhan 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

Filtering in the APEX Interactive Grid

Remember Oracle Forms? One of the nice features of Forms was the use of GLOBAL items. More or less comparable to Application Items in APEX. These GLOBALS where often used to pre-query data. For example you queried Employee 200 in Form A, then opened Form B and on opening that Form the Employee field is filled with that (GLOBAL) value of 200 and the query was executed. So without additional keys strokes or entering data, when switching to another Form a user would immediately see the data in the same context. And they loved that. In APEX you can create a similar experience using Application Items (or an Item on the Global Page) for Classic Reports (by setting a Default Value to a Search Item) and Interactive Reports (using the  APEX_IR.ADD_FILTER  procedure). But what about the Interactive Grid? There is no APEX_IG package ... so the first thing we have to figure out is how can we set a filter programmatically? Start with creating an Interactive Grid based upon the good o...

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 ...

Stop using validations for checking constraints !

 If you run your APEX application - like a Form based on the EMP table - and test if you can change the value of Department to something else then the standard values of 10, 20, 30 or 40, you'll get a nice error message like this: But it isn't really nice, is it? So what do a lot of developers do? They create a validation (just) in order to show a nicer, better worded, error message like "This is not a valid department".  And what you then just did is writing code twice : Once in the database as a (foreign key) check constraint and once as a sql statement in your validation. And we all know : writing code twice is usually not a good idea - and executing the same query twice is not enhancing your performance! So how can we transform that ugly error message into something nice? By combining two APEX features: the Error Handling Function and the Text Messages! Start with copying the example of an Error Handling Function from the APEX documentation. Create this function ...