|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV SYS-CON.TV WEBCASTS |
POWERBUILDER LINKS YOU MUST CLICK ON DataWindows Exploring DataWindow Display Formats
Getting more than simple data formatting from display formats
Mar. 14, 2007 12:00 PM
DataWindow display formats aren't a big secret. Most PowerBuilder developers use them to format numeric, date, time, and string values properly. Such display formats are usually straightforward and contain characters that have special meaning for a specific datatype like '#' for numeric values or '@' for string values. However, the DataWindow display format is a very powerful tool and you can get more than simple data formatting. This article explores what you can do with DataWindow display formats demonstrating a few tricks.
An interesting thing is that the whole display format string (the display format is a string, isn't it?) can contain only regular characters. In this case, the display format string is displayed itself instead of data. For example, if you specify qwerty as the display format for a string column, you get the result shown in Figure 2. It may seem useless unless you build the display format string dynamically using a DataWindow expression for the Format DataWindow object property.
Embellishing Special Values if(string( date_val, 'dd.mm.yyyy') = '11.11.1111', '\U\n\k\n\o\w\n', '[shortdate];\E\m\p\t\y' ) The result is shown in Figure 3. Two things are worth mentioning in this example. First, note the use of backslashes before each character in the format strings. It guarantees a more robust result because the backslash tells PowerBuilder not to try to interpret the display format but simply display the characters as they are. Second, note that the expression for the display format for a column refers to the value of the column. This is a very powerful technique, and it will be explored further in this article.
Decoding Values case( color when 1 then 'Red' when 2 then 'Green' when 3 then 'Blue' else 'Unknown' ) The result is shown in Figure 5. As you noticed, the result is pretty much the same as using the Code Table for the Edit DataWindow column type. However, sometimes this property can't be used unlike display formats that can. We'll come back to decoding values a bit later.
Sorting Values The problem can be easily solved if the number of the month is used in the data. In this case the columns are sorted properly as shown in Figure 7. But we don't want the month numbers to be displayed. To hide them, the following expression can be used for the Format DataWindow column property: mid( month, 3). The result is shown in Figure 8. Note how part of the data value is used as the display format string. Using string values in display formats displayed as they are doesn't look useless as it did in the example with the "qwerty" string, does it?
Decoding Lists of Values We'd like to display a list of colors on the intersection of a month and a laboratory, e.g., it would be 'Red Green Blue' for January, Lab 1, just 'Blue' for February, Lab 1, then 'Red Green' for January, Lab 2, and so on. One of the possible ways to do this is by using the DataWindow column display format. We have to code the colors in such a way that each code could be detected in the sum (on the condition that the sum can contain only unique codes, that is the same code can't be added more than one time). For purposes of illustration it's enough to make each color occupy a certain decimal position in the code. The same lookup table with the changed codes is shown in Figure 10. As you can see, if we sum up the codes, the rightmost one will tell us if the red color is here, the next one will tells us about green, and the leftmost tells about blue. Now we can build our CrossTab DataWindow. The result is shown in Figure 11. Note the months. They are formatted as I described earlier. Now, we need to decode the lists of colors in each cell. We can do so with the following expression for the Format DataWindow column property:
if( mid( string( color_code, '000'), 3, 1) = '1', 'Red ', '' ) + The final result is shown in Figure 12.
Conclusion PBDJ LATEST STORIES . . .
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK BREAKING POWERBUILDER / SYBASE NEWS
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||