<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Highlight clicked row from a table using javascript in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Highlight-clicked-row-from-a-table-using-javascript/m-p/518045#M34745</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/112007"&gt;@D2SI&lt;/a&gt;&amp;nbsp;Following requirement is confusing... "&lt;STRONG&gt;But instead of highlighting a row based on a value, I would like to highlight the clicked row"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;If you want clicked Row to be highlighted try the following Run anywhere example on similar lines as yours.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screen Shot 2020-09-05 at 10.49.56 PM.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/10663iE7D91A2F91793576/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2020-09-05 at 10.49.56 PM.png" alt="Screen Shot 2020-09-05 at 10.49.56 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Following is the Simple XML Dashboard:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;dashboard script="table_highlight_row_on_cell_click.js"&amp;gt;
  &amp;lt;label&amp;gt;Table Clicked Row Highlight&amp;lt;/label&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;html&amp;gt;
        &amp;lt;style&amp;gt;
          #highlight table tr.highlighted{
            border-style: solid !important;
            border-color: skyblue !important;
            background: orange !important;
          }
          #highlight table tr.highlighted td{
            background: orange !important;
            border: none !important;
            -webkit-box-shadow: none !important;
            box-shadow: none !important;
          }
        &amp;lt;/style&amp;gt;
      &amp;lt;/html&amp;gt;
      &amp;lt;table id="highlight"&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;index=_internal sourcetype=splunkd
| stats count by log_level&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-24h@h&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
          &amp;lt;sampleRatio&amp;gt;1&amp;lt;/sampleRatio&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="count"&amp;gt;100&amp;lt;/option&amp;gt;
        &amp;lt;option name="dataOverlayMode"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;cell&amp;lt;/option&amp;gt;
        &amp;lt;option name="percentagesRow"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="refresh.display"&amp;gt;progressbar&amp;lt;/option&amp;gt;
        &amp;lt;option name="rowNumbers"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="totalsRow"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="wrap"&amp;gt;true&amp;lt;/option&amp;gt;
        &amp;lt;drilldown&amp;gt;
          &amp;lt;set token="tokValue2"&amp;gt;$click.value2$&amp;lt;/set&amp;gt;
        &amp;lt;/drilldown&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/dashboard&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;Following is the required JavaScript&amp;nbsp;&lt;STRONG&gt;table_highlight_row_on_cell_click.js&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;require([
    'underscore',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/tableview',
    'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView) {
     // Color Clicked Row of table with id #highlight
     $(document).on("click","#highlight",function(){
        // Apply class of the cells to the parent row in order to color the whole row
        $("#highlight table").find('td.highlighted').each(function() {
            $("#highlight table tr").removeClass("highlighted");
            $(this).parents('tr').addClass(this.className);
        });
     });
});&lt;/LI-CODE&gt;</description>
    <pubDate>Sat, 05 Sep 2020 17:32:33 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2020-09-05T17:32:33Z</dc:date>
    <item>
      <title>Highlight clicked row from a table using javascript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Highlight-clicked-row-from-a-table-using-javascript/m-p/517997#M34727</link>
      <description>&lt;P&gt;Hello there!&lt;/P&gt;&lt;P&gt;I am trying to highlight a table row whenever clicked:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="screen.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/10660iA5B1A4A8F3470F63/image-size/large?v=v2&amp;amp;px=999" role="button" title="screen.png" alt="screen.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;This is the JavaScript I use to highlight a row based on a cell string value:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;require([
    'underscore',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/tableview',
    'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView) {

    var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
        canRender: function(cell) {
            // Enable this custom cell renderer for status field
            return _(["host"]).contains(cell.field);
        },
        render: function($td, cell) {
            // Add a class to the cell based on the returned value
            var value = cell.value;

            // Apply interpretation for status field
            // Since we have picked only one row for applying range Class, following if is not required.
            if (cell.field === "host") {
                //Add range class based on cell values.
                if (value == "test") {
                    $td.addClass("range-cell").addClass("range-green");
                }
            }

            // Update the cell content with string value
            $td.text(value).addClass('string');
        }
    });

    mvc.Components.get('highlight').getVisualization(function(tableView) {

        tableView.on('rendered', function() {
            // Add a delay to ensure Custom Render applies to row without getting overridden with built in reder.
            setTimeout(function(){
                // Apply class of the cells to the parent row in order to color the whole row
                tableView.$el.find('td.range-cell').each(function() {
                    $(this).parents('tr').addClass(this.className);
                });
            },100);
        });

        // Add custom cell renderer, the table will re-render automatically.
        tableView.addCellRenderer(new CustomRangeRenderer());
    });
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works with this dashboard:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;dashboard script="script.js"&amp;gt;
  &amp;lt;label&amp;gt;test&amp;lt;/label&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;table id="highlight"&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;| makeresults 
| eval host="test" 
| append 
    [| makeresults 
    | eval host="hello"]
| table host&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;0&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;cell&amp;lt;/option&amp;gt;
        &amp;lt;drilldown&amp;gt;
          &amp;lt;set token="clicked_row_tok"&amp;gt;$click.value$&amp;lt;/set&amp;gt;
        &amp;lt;/drilldown&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;title&amp;gt;$def$&amp;lt;/title&amp;gt;
      &amp;lt;html&amp;gt;
        &amp;lt;style&amp;gt;
          #highlight tr.range-green td {
              background-color: #F2B827 !important;
          }
        &amp;lt;/style&amp;gt;
      &amp;lt;/html&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/dashboard&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But instead of highlighting a row based on a value, I would like to highlight the clicked row (token $clicked_row_tok$)&lt;/P&gt;&lt;P&gt;So I guess I have to implement something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;    // Access the "default" token model
    var defaultTokenModel = mvc.Components.get("default");
    defaultTokenModel.on("change:clicked_row_tok", function(newTokenName, clicked_row_tok, options) {
        ...
        }
    });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To be able to do this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;if (cell.field == clicked_row_tok) {&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;But I am struggling mixing them both so I am here for help &lt;span class="lia-unicode-emoji" title=":folded_hands:"&gt;🙏&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Sep 2020 05:57:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Highlight-clicked-row-from-a-table-using-javascript/m-p/517997#M34727</guid>
      <dc:creator>D2SI</dc:creator>
      <dc:date>2020-09-05T05:57:35Z</dc:date>
    </item>
    <item>
      <title>Re: Highlight clicked row from a table using javascript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Highlight-clicked-row-from-a-table-using-javascript/m-p/518045#M34745</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/112007"&gt;@D2SI&lt;/a&gt;&amp;nbsp;Following requirement is confusing... "&lt;STRONG&gt;But instead of highlighting a row based on a value, I would like to highlight the clicked row"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;If you want clicked Row to be highlighted try the following Run anywhere example on similar lines as yours.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screen Shot 2020-09-05 at 10.49.56 PM.png" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/10663iE7D91A2F91793576/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2020-09-05 at 10.49.56 PM.png" alt="Screen Shot 2020-09-05 at 10.49.56 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Following is the Simple XML Dashboard:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;dashboard script="table_highlight_row_on_cell_click.js"&amp;gt;
  &amp;lt;label&amp;gt;Table Clicked Row Highlight&amp;lt;/label&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;html&amp;gt;
        &amp;lt;style&amp;gt;
          #highlight table tr.highlighted{
            border-style: solid !important;
            border-color: skyblue !important;
            background: orange !important;
          }
          #highlight table tr.highlighted td{
            background: orange !important;
            border: none !important;
            -webkit-box-shadow: none !important;
            box-shadow: none !important;
          }
        &amp;lt;/style&amp;gt;
      &amp;lt;/html&amp;gt;
      &amp;lt;table id="highlight"&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;index=_internal sourcetype=splunkd
| stats count by log_level&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-24h@h&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
          &amp;lt;sampleRatio&amp;gt;1&amp;lt;/sampleRatio&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="count"&amp;gt;100&amp;lt;/option&amp;gt;
        &amp;lt;option name="dataOverlayMode"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;cell&amp;lt;/option&amp;gt;
        &amp;lt;option name="percentagesRow"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="refresh.display"&amp;gt;progressbar&amp;lt;/option&amp;gt;
        &amp;lt;option name="rowNumbers"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="totalsRow"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="wrap"&amp;gt;true&amp;lt;/option&amp;gt;
        &amp;lt;drilldown&amp;gt;
          &amp;lt;set token="tokValue2"&amp;gt;$click.value2$&amp;lt;/set&amp;gt;
        &amp;lt;/drilldown&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/dashboard&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;Following is the required JavaScript&amp;nbsp;&lt;STRONG&gt;table_highlight_row_on_cell_click.js&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;require([
    'underscore',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/tableview',
    'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView) {
     // Color Clicked Row of table with id #highlight
     $(document).on("click","#highlight",function(){
        // Apply class of the cells to the parent row in order to color the whole row
        $("#highlight table").find('td.highlighted').each(function() {
            $("#highlight table tr").removeClass("highlighted");
            $(this).parents('tr').addClass(this.className);
        });
     });
});&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 05 Sep 2020 17:32:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Highlight-clicked-row-from-a-table-using-javascript/m-p/518045#M34745</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-05T17:32:33Z</dc:date>
    </item>
    <item>
      <title>Re: Highlight clicked row from a table using javascript</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Highlight-clicked-row-from-a-table-using-javascript/m-p/518047#M34747</link>
      <description>&lt;P&gt;Wow! Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Sat, 05 Sep 2020 17:54:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Highlight-clicked-row-from-a-table-using-javascript/m-p/518047#M34747</guid>
      <dc:creator>D2SI</dc:creator>
      <dc:date>2020-09-05T17:54:37Z</dc:date>
    </item>
  </channel>
</rss>

