Page 1 of 1
Changing field colors through broker
Posted: Sun Jun 26, 2011 3:06 pm
by igalperry
Jan,
Is it possible to access report fields from the broker in order to set their background color or other visual properties?
Thank you,
Igal
Re: Changing field colors through broker
Posted: Sun Jun 26, 2011 5:40 pm
by JanSchenkel
Hi Igal,
It depends on what exactly you're trying to achieve.
One method is to use a formatter helper function in your data broker, and use the 'htmlText' format on the data field. Such a formatter helper function could look something like:
Code: Select all
function formattedData pData
local tFormattedData
put "<p>" into tFormattedData
if pData is a number and pData < 0 then
put "<font color=" & quote & "red" & quote & ">" & pData after tFormattedData
else if pData is a number and pData = 0 then
put "<font bgcolor=" & quote & "yellow" & quote & ">" & pData after tFormattedData
else
put htmlSafe(pData) after tFormattedData
end if
put "</p>" after tFormattedData
return tFormattedData
end formattedData
function htmlSafe pData
replace "&" with "&" in pData
replace quote with """ in pData
replace "<" with "<" in pData
replace ">" with ">" in pData
return pData
end htmlSafe
and then your data field would have an expression similar to:
Code: Select all
formattedData(sCustomer["balance"])
If the customer's balance is negative, the balance will be printed in red; if the balance is 0 then the balance will pe printed in black with a yellow background. Admittedly a silly example, but quite a nifty way if all you need is to manipulate data field formatting.
The only other option (right now) is to use multiple items on the layout, each with the proper formatting in place, and with mutually exclusive printing conditions. This can be applied to any type of report item (not just data fields) but can be a bit cumbersome to setup.
HTH,
Jan Schenkel.