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

How to create neatly formatted Excel documents using PL/SQL?

If there is a requirement to produce output from an application into Excel, you would probably create a CSV (Comma Separated File) with the data and start Excel to show the data - at least that's what I did...until now. The drawback of this solution is that you could only produce data and no nice layout. But Excel is also capable of opening HTML-files and using this you could create Excel files with data and magnificent layout! Let me give an example: 1. Create a procedure to show the data in formatted in an HTML table. CREATE OR REPLACE PROCEDURE display_emp_list IS v_emp_count NUMBER(5); v_empno NUMBER(8); v_ename VARCHAR2(50); v_job emp.job%TYPE; v_sal emp.sal%TYPE; v_bg_color VARCHAR2(10) := ''; CURSOR c_emp IS SELECT empno, initcap(ename), job, sal FROM emp ORDER BY ename; BEGIN SELECT COUNT(*) INTO v_emp_count FROM emp; owa_util.mime_header('application/ms-excel', FALSE); htp.p('Content...

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

APEX ReadOnly Pages - The easy way

If your Oracle APEX Application requires different types of access - full access or readonly - for different types of users, you can specify a Read Only Condition on Page level (or Region, Item, Button, etc.).  You can set an Authorization Scheme on Application level, so it'll be applied to all pages. So if you have an Authorization Scheme named 'User Can Access Page' defined by a PL/SQL function like this: return apex_authorization.user_can_access_page ( p_app_id  => :APP_ID , p_page_id => :APP_PAGE_ID , p_user    => :APP_USER );  then you can code all the logic in the database using the APEX Repository, your own tables or a combination to define whether a user has access to that page or not. But alas it is not possible to define something similar Application wide for a Read Only condition. You can specify an Authorization Scheme 'User has Read Only Access' using a similar signature as the one above and use that on each and e...