Dashboards & Visualizations

Row Renderer? How to color a whole row when condition is met on one of its cells?

jamesvz84
Communicator

I have used the BaseCellRenderer to color individual cells based on conditions and it had worked great for me.

Now I need to color a whole row whenever a condition is met on one of its cells.

Is there some type of Row Renderer I can use to color the table row? If not, what would be the best way to accomplish this?

Tags (3)
0 Karma
1 Solution

LukeMurphey
Champion

This is a little complicated because the cell is not put into the DOM so you cannot move up to the parent to style it.

You can do it with some complicated CSS though. Here's how:

  1. Move or copy the row that has the data that you want to use for declaring how the row will be styled to the first column. If you don't really want it to be the first column, then just include it twice and hide the first one with some CSS (in dashboard.css or application.css).
  2. Add a cell renderer that defines a class that will be used for determining the color of the row; have it put the class information to the first column.
  3. Add application CSS (in dashboard.css or application.css) that will use adjacent sibling selectors to style the TD elements based on the class in the first cell. The CSS would look something like this (assuming that your cell renderer applies the class "makerowred" to the first cell):

    /* styles the first cell */
    td.makerowred{
    color: red;
    }

    /* styles the second cell */
    td.makerowred + td{
    color: red;
    }

    /* styles the third cell */
    td.makerowred + td + td{
    color: red;
    }

View solution in original post

LukeMurphey
Champion

This is a little complicated because the cell is not put into the DOM so you cannot move up to the parent to style it.

You can do it with some complicated CSS though. Here's how:

  1. Move or copy the row that has the data that you want to use for declaring how the row will be styled to the first column. If you don't really want it to be the first column, then just include it twice and hide the first one with some CSS (in dashboard.css or application.css).
  2. Add a cell renderer that defines a class that will be used for determining the color of the row; have it put the class information to the first column.
  3. Add application CSS (in dashboard.css or application.css) that will use adjacent sibling selectors to style the TD elements based on the class in the first cell. The CSS would look something like this (assuming that your cell renderer applies the class "makerowred" to the first cell):

    /* styles the first cell */
    td.makerowred{
    color: red;
    }

    /* styles the second cell */
    td.makerowred + td{
    color: red;
    }

    /* styles the third cell */
    td.makerowred + td + td{
    color: red;
    }

martin_mueller
SplunkTrust
SplunkTrust

Bugger, sounds as if the renderer is getting the td before it's been hung into the DOM tree... and there's no parent selector in CSS either.

You could move the getting and CSS'ing of the parent into a delayed function, but that'd be quite ugly programming practice. Might work as a QnD temporary solution though.

jamesvz84
Communicator

I tried to get a hold of its parent using .parent() and .closest('tr') functions, but neither worked. I debugged using chrome and it seems like $td has no parent. Is there some other way to get its parent?

martin_mueller
SplunkTrust
SplunkTrust

Your JS renderer does have access to the td element, right? If so you may be able to grab hold of its parent, the tr element, and set its CSS or class attributes.

0 Karma

jamesvz84
Communicator

No, I am using simple xml with

on top. This allows me to use Javascript to apply a renderer.

0 Karma

barakreeves
Splunk Employee
Splunk Employee

Are you using Django bindings?

0 Karma
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...