Dashboards & Visualizations

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

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

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

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)

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

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

Splunk Employee
Splunk Employee

sideviewapps.com

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

Communicator

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

0 Karma

Communicator

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

0 Karma