Dashboards & Visualizations

Does 4.2 have any capabilities to set a row color based on a field example

kbecker
Communicator

With the release of 4.2 I was wondering if it is now possible to set the color of a table row based on the value of one of the fields in that row. For example, I have a field that will display "Violation" if certain criteria is met, so if the status field in a row is equal to this value I would like the whole table row to be red.

Thanks...

1 Solution

araitz
Splunk Employee
Splunk Employee

You can hack this up without too much trouble. I also know a hired gun that can provide services for this sort of thing.

I am assuming you want a row in a table to change color - event viewer would be just a little different. If you have more than one table, the implementation would be slightly different as well.

$SPLUNK_HOME/etc/apps/your_app/appserver/static/application.js

switch (Splunk.util.getCurrentView()) {
    case "the_dashboard_in_question": case "another_dashboard_in_scope":
        Splunk.Module.SimpleResultsTable = $.klass(Splunk.Module.SimpleResultsTable, {
            onResultsRendered: function() {
                this.decorateRange(this.container);
            },  
            decorateRange: function(container) {
                var colorMap = {black: '#000000', red: '#bb2121', orange: '#e67918', green: '#72c72d', blue: '#4da6df'};
                var _this = this;
                $('td', container).each(function() {
                    var coordinates = _this.getXYCoordinates($(this));
                    if (_this.getColumnName(coordinates.x, $(this)).toLowerCase() == 'range') {
                        $(this).css('background-color', colorMap[$(this).text().toLowerCase()]);
                    }   
                }); 
            },  
        }); 
}

View solution in original post

sideview
SplunkTrust
SplunkTrust

The Table module from Sideview Utils can do this now. It has a rowClass param, and you can refer to one or more field values within that param.

For instance if you had this Table:

<module name="Table">
  <param name="hiddenFields">myClassField</param>
  <param name="rowClass">$row.fields.myClassField$</param>
</module>

Courtesy of the "rowClass" field, the Table would happily give each row a CSS classname that was equal to the "myClassField" field value from the given row.

And courtesy of the "hiddenFields" param, the myClassField wont actually be displayed as a column in the Table.

The Table module came out in Sideview Utils 2.2, you can get the Sideview Utils app for free for internal use, from the sideview site at http://sideviewapps.com/apps/sideview-utils, and note that if you think you have Sideview Utils already there's a good chance that it's the much older version from Splunkbase, (1.3.5), not the latest version from Sideview (2.2.10)

araitz
Splunk Employee
Splunk Employee

You can hack this up without too much trouble. I also know a hired gun that can provide services for this sort of thing.

I am assuming you want a row in a table to change color - event viewer would be just a little different. If you have more than one table, the implementation would be slightly different as well.

$SPLUNK_HOME/etc/apps/your_app/appserver/static/application.js

switch (Splunk.util.getCurrentView()) {
    case "the_dashboard_in_question": case "another_dashboard_in_scope":
        Splunk.Module.SimpleResultsTable = $.klass(Splunk.Module.SimpleResultsTable, {
            onResultsRendered: function() {
                this.decorateRange(this.container);
            },  
            decorateRange: function(container) {
                var colorMap = {black: '#000000', red: '#bb2121', orange: '#e67918', green: '#72c72d', blue: '#4da6df'};
                var _this = this;
                $('td', container).each(function() {
                    var coordinates = _this.getXYCoordinates($(this));
                    if (_this.getColumnName(coordinates.x, $(this)).toLowerCase() == 'range') {
                        $(this).css('background-color', colorMap[$(this).text().toLowerCase()]);
                    }   
                }); 
            },  
        }); 
}

sideview
SplunkTrust
SplunkTrust

Note Sideview answer below is actually to use the Table module, which you can get in latest Sideview Utils app (currently 2.4.5) It's quite easy to use, has extensive docs in the app itself, you can set up custom row bgcolors quite easily and aside from the custom CSS to pick your colors, it doesn't require any custom code. http://sideviewapps.com/apps/sideview-utils

0 Karma

araitz
Splunk Employee
Splunk Employee

sideviewapps.com

pomtest01
New Member

Hi araitz
From your post "...You can hack this up without too much trouble. I also know a hired gun that can provide services for this sort of thing....". I am interested in the hired gun as I js is too much for me. Could u introduce the hired gun to me? Thx

0 Karma

netwrkr
Communicator

Not that I'm aware of. Would the 'highlight' command help?

0 Karma

kbecker
Communicator

Looks like the highlight command doesn't work with tables.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...