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!
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
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
nice solution. Thanks for sharing your idea.
Best regards,
Tobias
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
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
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
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.
Can you please tell me how u are updating the database by clicking the check mark.
And what are those parameters ,,
thanks
Tauceef
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
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
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.
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).
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
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