Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to change the background color of oracle apex classic report on based on condition

Pankaj Kumar MandalApr 25 2014 — edited Apr 29 2014

I am working oracle apex 4.2 environment, where I am developing report, in which I wan to implement the color of row should change according to column value.

For example I was working with below query

select

case

when sal > 1000 then

'<span style=background-color:red>'

else

'<span style=background-color:green>'

end,

"EMPNO",

"ENAME",

"JOB",

"MGR",

"HIREDATE",

"SAL",

"COMM",

"DEPTNO"

from EMP

But it was not able to change the color of the row. Please guide me.

Comments

Sunil Bhatia

Hi Pankaj,

Atleast search forum once before posting question. Exactly same requirement with "Jari" correct answer

You can extend this to specific row, etc

Thanks

Sunil Bhatia

Pankaj Kumar Mandal

I already check it and it was not meeting my requirement thats why I posted the question in forum, In my case as the query is dynamically generated from function. so how to mentioned the column name SAL in javascript.

<script type="text/javascript">
$(function(){
$('##REGION_ID# input[name="f01"]').each(function(i){
  $(this).parents("tr:first").find('[headers="SAL"]').css({"background-color":$v(this)});
});
});
</script>

Sunil Bhatia

Hi Pankaj,

In original question, you mentioned

I was working with below query

select

case

when sal > 1000 then

'<span style=background-color:red>'

else

'<span style=background-color:green>'

end,

"EMPNO",

"ENAME",

"JOB",

"MGR",

"HIREDATE",

"SAL",

"COMM",

"DEPTNO"

from EMP

Nowhere it signifies, you are generating it from function? Did it?

And if you read it correctly, jquery can be handled by using classes.

You can write a specific class in the span which is generated by your function. And on load of page, that span class can carry background color.

fac586

Pankaj Kumar Mandal wrote:

I already check it and it was not meeting my requirement thats why I posted the question in forum, In my case as the query is dynamically generated from function. so how to mentioned the column name SAL in javascript.

How is the query "dynamically generated"? What is dynamic: Projection? Source? Predicates? All of them?

What is the logic that determines the colour change?

Pankaj Kumar Mandal

@Sunil Bhatia

Yeah I missed that out and surely I will try out the your suggestion and let you know if it worked out or not.

Pankaj Kumar Mandal

Hi,

I have developimg a centralized system for reporting purpose where I am putting a query in table from where I am passing some parameter which is stored in a table.

The final thing is I have created single report region for the same in the source there is  function which takes report_id as parameter and returning that query depending on the report name selected in LOV, therefore  the report column and data changes according to the query.

For color changing I am storing the condition in a table with respect to report_id and in the function which is returning query I am checking condition and modifying the original query

For e.g. my original query is which is stored in query table

as

ID             Query

1              select "EMPNO",  "ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO" from EMP

and my condition is store in condition as below:

report_id      condition      color

1                SAL>1000      red

1                 default           green

In query returning function, it checks for the condition and return the below query

select

case

when sal > 1000 then

'<span style=background-color:red>'

else

'<span style=background-color:green>'

end,

"EMPNO",

"ENAME",

"JOB",

"MGR",

"HIREDATE",

"SAL",

"COMM",

"DEPTNO"

from EMP

This is the whole logic in the application

fac586

Pankaj Kumar Mandal wrote:

For color changing I am storing the condition in a table with respect to report_id and in the function which is returning query I am checking condition and modifying the original query

For e.g. my original query is which is stored in query table

as

ID             Query

1              select "EMPNO",  "ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO" from EMP

and my condition is store in condition as below:

report_id      condition      color

1                SAL>1000      red

1                 default           green

In query returning function, it checks for the condition and return the below query

select

case

when sal > 1000 then

'<span style=background-color:red>'

else

'<span style=background-color:green>'

end,

"EMPNO",

"ENAME",

"JOB",

"MGR",

"HIREDATE",

"SAL",

"COMM",

"DEPTNO"

from EMP

This is the whole logic in the application

Can there be more than one condition and a default for each report?

Pankaj Kumar Mandal

Yes there can be more than one condition and also there will be a default value for each report.

GhanaApexDeveloper

Hi Pankaj,

please check this thread

https://community.oracle.com/thread/3551474

Thanks

Benjamin

Pankaj Kumar Mandal

Hi,

I implemented and converted the column to STANDARD but it is not work that way also.

fac586

Pankaj Kumar Mandal wrote:

I have developimg a centralized system for reporting purpose where I am putting a query in table from where I am passing some parameter which is stored in a table.

This is not a good idea. Why are you doing this? Explain why this approach is being used.

How many of these queries are there? Where do they come from?

The final thing is I have created single report region for the same in the source there is  function which takes report_id as parameter and returning that query depending on the report name selected in LOV, therefore  the report column and data changes according to the query.

Are you using the Use Generic Column Names option on the report source? If so, how do you get the report column headings?

Pankaj Kumar Mandal

There are around 100 queries and we can add more for which application creates report dynamically, in short I have developed a reporting framework, where any report can be developed and the data will be seen.

The column  names are coming from a table which also comes form a function which returns colon separated column name.

Everything is working fine I have able to see the report, report data and column name, I just want to add background color depending on the condition.

1 - 12
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on May 27 2014
Added on Apr 25 2014
12 comments
10,518 views