Hide number when zero

Questions and answers for designing and implementing forms in Servoy

Re: Hide number when zero

Postby Ron » Sun Jul 19, 2009 8:55 am

I tried the calcfield [Name: tekstcalculatie / returned type: tekst / displayed type: html ] and can display the number bold.
However backgroundcolor still won't work, so it must be a wrong html code.

function tekstcalculatie()
{
if ( getal == 100 )
{
var a = '<html><body bgcolor="#FF5566">' +getal+ '</body></html>'
return a
}
var b = getal
return b
}
Ron
 
Posts: 315
Joined: Fri May 23, 2003 12:30 am
Location: Netherlands

Re: Hide number when zero

Postby ROCLASI » Sun Jul 19, 2009 11:51 am

Hi Ron,
Ron wrote:@Robert:
This is my code:
for ( var i = 1 ; i < forms.tweede.controller.getMaxRecordIndex() ; i++ )
{
forms.tweede.controller.setSelectedIndex(i)
if (forms.tweede.getal == 10)
{
forms.tweede.elements.ccc.bgcolor = '#FF3366'
}
}


As you noticed yourself you can't set an element per row in list- or tableview. It will change all rows then.

Ron wrote:@Riccardino:
This calculationfield code does'nt work:
'<html><body bgcolor="#FF3366">' + getal + '</body></html>'

You need to use a table to get the background color working. So your code will look like this:
Code: Select all
function tekstcalculatie()
{
  if ( getal == 100 ) {
    var a = '<html><table width="100%" bgcolor="#FF5566"><tr><td>' +getal+ '</td></tr></table></html>'
    return a   
  } else {
    var b = getal
    return b
  }   
}
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Hide number when zero

Postby Ron » Sun Jul 19, 2009 12:18 pm

It even works without table tag Robert!
Thank you (and Ric.) for your assistance.
Regards,
Ron

function tekstcalculatie()
{
if ( getal == 100 ) {
var a = '<html><body bgcolor="#FF5566">' +getal+ '</body</html>'
return a
} else {
var b = '<html><body bgcolor="#FFFFFF">' +getal+ '</body</html>'
return b
}
}
Ron
 
Posts: 315
Joined: Fri May 23, 2003 12:30 am
Location: Netherlands

Re: Hide number when zero

Postby Riccardino » Sun Jul 19, 2009 12:32 pm

Ron wrote:It even works without table tag Robert!
Thank you (and Ric.) for your assistance.


You're welcome. Remember that you can also use those calcs in row background colors: it's a very useful techinque if you want to make some record stand out in a list (say: all the orders "IN PROGRESS" can have a green background etc.)
ciao, ric
User avatar
Riccardino
 
Posts: 911
Joined: Thu Apr 24, 2003 11:42 am
Location: Ferrara, Italy

Re: Hide number when zero

Postby ROCLASI » Sun Jul 19, 2009 12:47 pm

Ron wrote:It even works without table tag Robert!

I stand corrected :)
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Hide number when zero

Postby nromeou » Thu Jan 26, 2012 9:32 pm

Hi,
Has anyone figured out if it is possible to hide zero values??
I'm in dire need of it.

Thanks for the help
nromeou
 
Posts: 215
Joined: Fri Sep 18, 2009 8:38 pm
Location: Montevideo, Uruguay

Re: Hide number when zero

Postby jcompagner » Fri Feb 10, 2012 4:54 pm

column converter? so convert 0 to null?
But that thats also in scripting suddenly a null
In 6.1 you have more options there we also have a UI Converter. so that is just for the ui itself
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: Hide number when zero

Postby amcgilly » Thu Jan 30, 2014 11:21 am

I can't find documentation on how to set up a UI Converter. Can someone explain how you use these, and specifically how I would use it to convert zeros to nulls? Thanks.
Adrian McGilly
Servoy Developer

Image
amcgilly
 
Posts: 375
Joined: Fri Dec 09, 2005 12:03 am
Location: San Francisco, CA

Re: Hide number when zero

Postby david » Thu Jan 30, 2014 7:40 pm

Check out our fractions project on Servoy Forge: https://www.servoyforge.net/projects/fractions/wiki

Pretty clear instructions in the wiki plus the code should get you pointed in the right direction.
David Workman, Kabootit

Image
Everything you need to build great apps with Servoy
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.

Re: Hide number when zero

Postby amcgilly » Thu Feb 27, 2014 11:02 pm

I got this to work using a UI Converter. It works on any kind of dataprovider - aggregations, calcs, db columns, format vars, etc. When used on db columns it does not affect the value in the db - it only affects the presentation.

Here's what I'm doing:

Create a global method called showZeroAsBlank():

Code: Select all
function showZeroAsBlank(number) {
   if (number == 0)
      return null
   else
      return number   
}


Now for each field where you want zeros to display as blanks, open the Format property dialog and do the following:
  • Check 'Use a UI Converter'
  • Select 'GlobalMethodConverter' from the dropdown
  • Leave the first two lines in the list blank (fromObjectMethodName and type)
  • Set toObjectMethodName to the showZeroAsBlank method.
  • Specify a display format (e.g. #,##0.0) if you want - that will work in conjunction with the UI Converter.
  • Click OK and you're done.

I've only just started using this so proceed with caution - I may yet find problems with it.

Thanks to Johan Compagner and David Workman for pointing me in the right direction.
Adrian McGilly
Servoy Developer

Image
amcgilly
 
Posts: 375
Joined: Fri Dec 09, 2005 12:03 am
Location: San Francisco, CA

Re: Hide number when zero

Postby kwpsd » Fri Feb 28, 2014 6:48 pm

That's good to know. Thanks Adrian, et al.
Kim W. Premuda
San Diego, CA USA
User avatar
kwpsd
 
Posts: 687
Joined: Sat Jul 28, 2007 6:59 pm
Location: San Diego, CA USA

Previous

Return to Forms

Who is online

Users browsing this forum: No registered users and 2 guests

cron