Jump to content

Dataview Formatting

Recommended Posts

If you have looked at Dataviews, you have probably wondered about the DataView Format Control. The Dataview editor allows you to manipulate the values, but when it doesn't work it isn't clear what you can do (or what you are doing wrong).


An example format looks like:

Drive Fragmentation,0,000000,FFFFFF,2,None,0,,%,3,10,0,FF0000,FFFFFF,1,3,15,1,000000,FF0000,1

Multiple format codes are separated with the "|" character, for example:

Agent CPU Usage,A,,,2,,0,,%,3,90,1,FF0000,,1|Agent Memory Total,A,,,1,,0,,mb|Agent Memory Avail,A,,,1,,0,,mb|Agent Uptime,A,,,1,,0,, mins|Agent MAC,A,,,2,,0,,|Agent Status,1,FFFFFF,EE0000,2,,0,,,1,Online,0,FFFFFF,00EE00,1|

This is the meaning for the Format String:

[Column Name],[FontType],[ForeColor],[backColor],[Alignment],[OnNull],[FileDivider],[Prefix],[suffix],[Condition],[Value],[FontType],[ForeColor],[backColor],[Effect]

NOTE: . . . [Condition],[Value],[FontType],[ForeColor],[backColor],[Effect] may be repeated over and over. This will be evaluated in the order specified.


This is the meaning for each field:

  • Column Name: The name of the column in the dataview.
  • FontType: Specify font types by specifying the value associated with the font type. They can be used together (Add the values).
    Font Type Values - Bold=1, Italics=2, Underline=4, Strike Out=8
  • ForeColor, BackColor: You specify the foreground or background color by specifying a hex color value (RRGGBB) for this object (e.g.; FFFFFF for white).
  • Alignment: Specify alignment by specifying the value associated with the alignment type.
    Alignment Type Values - Left=0, Right=1, Center=2
  • OnNull: Enter any value you want displayed when the result is null.
  • FieldDivider: Enter a numeric value to divide the result by for visual display.
  • Prefix, Suffix: Value to append to the beginning or to the end of the result (e.g., $).
  • Condition: Indicate which comparer to utilize by specifying the value associated with the comparer.
    Comparers - Equals=1, NotEquals=2, GreaterThan=3, LessThan=4, Contains=5, Anything=6, In=7, Between=8
  • Value:Specify a value to compare result to.
  • Effect: Indicate whether to effect a column or row by specifying the associated value. To effect a column enter '1'. To effect a row enter '2'.


To look at an example in practice, in my Computer Status and Idle dataview, the "Agent Status" column is defined as:

CONVERT(IF(Computers.LastContact>DATE_ADD(NOW();;interval -7 Minute);;'Online';;'Offline') using utf8) as `Agent Status`

The format string is (with the field names added:

[Column Name]Agent Status,[FontType]1,[ForeColor]FFFFFF,[backColor]EE000,[Alignment]2,[OnNull],[FileDivider]0,[Prefix],[suffix],[Condition]1,[Value]Online,[FontType]0,[ForeColor]FFFFFF,[backColor]00EE00,[Effect]1

This has the effect of defining regular text as FontType 1 with the ForeColor as FFFFFF, BackColor as EE0000 (Bold White text on a Red Background). When the 'Agent Status' (Column Name) value equals (Condition 1) the word 'Online' (Value), the FontType is 0, with the ForeColor as FFFFFF, BackColor as 00EE00 (Normal White text on a Green Background). This change is only applied to the current field (Effect 1=Column).


And the result:


(Full Disclosure: I created the dataview mentioned above by adding the 'Agent Idle Time' column to the existing Agent Status dataview. The 'Agent Status' column formatting was already defined in the stock dataview with the settings explained here.)


Share this post

Link to post
Share on other sites

Oh that's great work it putting that info out like this! Thanks! I have to lock myself away and make sure nobody disturbs me when I'm trying to work these things into a data view. Or worse trying decipher an existing data view.

You can actually dress them up quite nicely with the formatting.

Regards Peter.

Share this post

Link to post
Share on other sites

Apologies for thread necro, but my question is directly related. How do you get formatting to occur for 3-4 different outputs?

"No Data"

For True, I want green background black font.
For False, I want red background white font.
For No Data, I want yellow background black font.
For "" (nothing/blank), I want no formatting.

Is this possible?? The challenge I am experiencing is that every field preceding the field I am applying this formatting to received the formatting for "No Data", even though none of the preceding fields for that row match (and even though there is no formatting applied to preceding fields of the same row).

I am hoping that through a constructive response I would better understand how multiple conditions for formatting works, especially in something to say "if = this, then do this, else nothing"

Edited by BlueToast

Share this post

Link to post
Share on other sites

I'm not sure that this is possible. I would try to do it in the Dataview Creator. But my suspicion is that since the formatting override is basically: "When condition is met, format this way" that there are not alternative options. You would have to define the formatting for the field multiple times, and I suspect that instead of being treated like multiple conditions, it will pick the last matching condition definition and use that. (Or the first. Or just crash and fail.)

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...