Want to take a look at a demo first before the steps to take to make it work? It's right here.
For this example, I will use a simple table named TASKS:
create table TASKS ( id number not null, ind_complete varchar2(1) not null, what varchar2(250) not null, complete_before date ); alter table TASKS add constraint TSK_PK primary key (id); alter table TASKS add constraint IND_COMPLETE_CHK check (ind_complete in ('Y', 'N'));To mark a task as "Done", create a procedure named MARK_TASK_COMPLETED:
create or replace procedure mark_task_completed (p_tsk_id in tasks.id%type) is begin update tasks tsk set tsk.ind_complete = 'Y' where tsk.id = p_tsk_id ; end mark_task_completed;Seed the table with some sample data:
insert into tasks (id ,ind_complete ,what ,complete_before) select rownum ,'N' ,'testing' || to_char(rownum) ,sysdate + rownum from dual connect by level <= 10;Now that the database side is done, we can turn our attention to APEX. To show images in the report, upload some in the Shared Components section.
the site of IconArchive.
Next create an Interactive Report, using the wizard. For the Query use the following:
select id tsk_id ,case ind_complete when 'Y' then 'ok' when 'N' then 'nok' end ind_complete ,what ,complete_before from tasksIn the above statement I used a case statement to translate the indicator to 'ok' or 'nok', matching the names of the images that I uploaded in the previous step.
When you run the report, it will look like:
Next is to change the Ind Complete column into an image and make it clickable. Make the following changes to the column attributes of the Ind Complete column:
The link text used in the image above consists of two parts; the first is the location of the images, #APP_IMAGES# and the second part is the name of the image that we want to display #IND_COMPLETE#. The latter is a neat trick (at least I think so) instead of using a "hardcoded" name for the image, the current value is used (see the query used for the Interactive Report, column IND_COMPLETE).
For the Link Attributes, we set the ID to the current TSK_ID by using the same syntax #TSK_ID# and add a class to which the Dynamic Action will respond - setCompleted.
When you inspect the report at this time (in the browser using something like FireBug), you will see that the image source is replaced just like we wanted:
Right click on "Dynamic Actions", choose "Create" from the context menu. Demo page, the procedure used to set the IND_COMPLETE is slightly different from the one described here. The procedure used will toggle the value, so you can mark the tasks completed as well as not completed. This is the source code for the procedure:
create or replace procedure mark_task_completed (p_tsk_id in tasks.id%type) is begin update tasks tsk set tsk.ind_complete = case ind_complete when 'Y' then 'N' when 'N' then 'Y' end where tsk.id = p_tsk_id ; end mark_task_completed;