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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...