<?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: Javascript tooltip showing results of a CSV lookup in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Javascript-tooltip-showing-results-of-a-CSV-lookup/m-p/410443#M118420</link>
    <description>&lt;P&gt;@alai&lt;BR /&gt;
Glad to help you.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Happy Splunking&lt;/STRONG&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Feb 2019 09:07:08 GMT</pubDate>
    <dc:creator>kamlesh_vaghela</dc:creator>
    <dc:date>2019-02-28T09:07:08Z</dc:date>
    <item>
      <title>Javascript tooltip showing results of a CSV lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Javascript-tooltip-showing-results-of-a-CSV-lookup/m-p/410439#M118416</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;we do have a table showing (besides other information) HTTP status codes. I'm trying to implement a tooltip that shows the corresponding status code description when hovering over with the mouse. The descriptions are in a CSV file which comes with the CIM.&lt;/P&gt;

&lt;P&gt;I found a useful blog (&lt;A href="https://www.splunk.com/blog/2014/01/29/add-a-tooltip-to-simple-xml-tables-with-bootstrap-and-a-custom-cell-renderer.html"&gt;Add a Tooltip to Simple XML Tables..&lt;/A&gt;) describing how a tooltip can be implemented. I tried to modify it by including a search / lookup but can't get it to work as expected:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require([
    'underscore',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/tableview',
    'splunkjs/mvc/searchmanager',
    'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView, SearchManager) {

        canRender: function(cell) {
            return cell.field === 'Status';
        },
        render: function($td, cell) {

            var mySearch = new SearchManager({
                "id": "my_search_id",
                "search": '| lookup cim_http_status_lookup status as "' + cell.value + '" OUTPUT status_description as stat_desc | table stat_desc'
            }, { tokens: true });

            var stat = cell.value;
            var stat_desc = mySearch.data("results");

            $td.html(_.template('&amp;lt;a href="#" data-toggle="tooltip" data-container="body" data-placement="top" title="&amp;lt;%- stat_desc%&amp;gt;"&amp;gt;&amp;lt;%- stat%&amp;gt;&amp;lt;/a&amp;gt;', {
                stat_desc: stat_desc,
                stat: stat
            }));

            // This line wires up the Bootstrap tooltip to the cell markup
            $td.children('[data-toggle="tooltip"]').tooltip();
        }
    });

    mvc.Components.get('nginx_access_expand_table').getVisualization(function(tableView) {

        // Register custom cell renderer
        tableView.table.addCellRenderer(new CustomTooltipRenderer());

        // Force the table to re-render
        tableView.table.render();
    });

});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks for your feedback.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 14:46:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Javascript-tooltip-showing-results-of-a-CSV-lookup/m-p/410439#M118416</guid>
      <dc:creator>alai</dc:creator>
      <dc:date>2019-02-27T14:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript tooltip showing results of a CSV lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Javascript-tooltip-showing-results-of-a-CSV-lookup/m-p/410440#M118417</link>
      <description>&lt;P&gt;Tooltip requires css library like bootstrap, have you imported them ? &lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 02:35:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Javascript-tooltip-showing-results-of-a-CSV-lookup/m-p/410440#M118417</guid>
      <dc:creator>divvyamehta</dc:creator>
      <dc:date>2019-02-28T02:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript tooltip showing results of a CSV lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Javascript-tooltip-showing-results-of-a-CSV-lookup/m-p/410441#M118418</link>
      <description>&lt;P&gt;Hello @alai,&lt;/P&gt;

&lt;P&gt;In below blog only main steps are mentioned which are important to implement tooltip feature in Table. I believe you have implemented full code for your dashboard.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://www.splunk.com/blog/2014/01/29/add-a-tooltip-to-simple-xml-tables-with-bootstrap-and-a-custom-cell-renderer.html"&gt;https://www.splunk.com/blog/2014/01/29/add-a-tooltip-to-simple-xml-tables-with-bootstrap-and-a-custom-cell-renderer.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Well, it seems you want to display value from the lookup table to display the &lt;CODE&gt;status description&lt;/CODE&gt; in a tooltip for respective &lt;CODE&gt;status&lt;/CODE&gt;. And you are executing a search to get a &lt;CODE&gt;status description&lt;/CODE&gt; from the lookup. &lt;/P&gt;

&lt;P&gt;Here I suggest you to incorporate lookup search in your table search and not need to execute search individually status wise. &lt;/P&gt;

&lt;P&gt;Check &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.4/SearchReference/Lookup"&gt;https://docs.splunk.com/Documentation/Splunk/7.2.4/SearchReference/Lookup&lt;/A&gt; link you will find the lookup examples.  &lt;/P&gt;

&lt;P&gt;With the single search, you can see my answer in the below post. You can achive the same thing without execute any other search.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/592103/how-can-i-show-multiple-values-on-a-tooltip-from-a.html"&gt;https://answers.splunk.com/answers/592103/how-can-i-show-multiple-values-on-a-tooltip-from-a.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;But I'm sharing a solution, what if we want to execute search incase Single search is not possible with Table. I'm taking your problem statement as an example.&lt;/P&gt;

&lt;P&gt;In your code, you have used &lt;CODE&gt;SearchManager&lt;/CODE&gt; to execute a search. But here I have used  &lt;CODE&gt;service&lt;/CODE&gt; to execute search and process results. &lt;/P&gt;

&lt;P&gt;Check &lt;A href="http://dev.splunk.com/view/javascript-sdk/SP-CAAAEFA"&gt;http://dev.splunk.com/view/javascript-sdk/SP-CAAAEFA&lt;/A&gt; for more information about &lt;CODE&gt;service.search&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;Below is the full implementation: You have to just copy-paste it to try. I have used sample searches. You can change it as per your need.&lt;/P&gt;

&lt;P&gt;test.xml&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard script="test.js" stylesheet="test.css"&amp;gt;
  &amp;lt;label&amp;gt;Tooltip on Table&amp;lt;/label&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;table id="tableTest"&amp;gt;
        &amp;lt;title&amp;gt;My Table&amp;lt;/title&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;| makeresults count=5 | eval num=1 | accum num |  eval Status="Hello Status "+num | table _time Status&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-15m&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="count"&amp;gt;10&amp;lt;/option&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="refresh.display"&amp;gt;progressbar&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/dashboard&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;test.js&lt;/STRONG&gt; &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; require([
    'underscore',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/tableview',
    'splunkjs/mvc/searchmanager',
    'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView,SearchManager) {
    var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
        canRender: function(cell) {
             return cell.field === 'Status';
        },
        render: function($td, cell) {
            var cell_value = cell.value;
            var searchQuery = '| makeresults | eval StatusTooltip="Hello from '+cell_value+' " | table StatusTooltip'
            var searchParams = {
                exec_mode: "blocking",
                earliest_time: "2012-06-20T16:27:43.000-07:00"
            };
            var service = mvc.createService();
            console.log("Wait for the search to finish...");

            service.search(
                searchQuery,
                searchParams,
                function(err, job) {
                    console.log("...done!\n");

                    // Get the job from the server to display more info
                    job.fetch(function(err){
                        // Get the results and display them
                        job.results({}, function(err, results) {
                            var fields = results.fields;
                            var rows = results.rows;
                            var ret_value=results.rows[0][0];
                            console.log(cell_value,ret_value);
                            console.log(fields);
                            console.log(rows);
                            $td.html(_.template('&amp;lt;a href="#" data-toggle="tooltip" data-container="body" data-placement="top" title="&amp;lt;%- stat_desc%&amp;gt;"&amp;gt;&amp;lt;%- stat%&amp;gt;&amp;lt;/a&amp;gt;', {
                                stat_desc: ret_value,
                                stat: cell_value
                            }));
                            $td.children('[data-toggle="tooltip"]').tooltip();
                        })
                    });
                }
            );             
        }
    });

    //List of table IDs to add icon
    var tableIDs = ["tableTest"];
    for (i=0;i&amp;lt;tableIDs.length;i++) {
        var sh = mvc.Components.get(tableIDs[i]);
        if(typeof(sh)!="undefined") {
            sh.getVisualization(function(tableView) {
                // Add custom cell renderer and force re-render
                tableView.table.addCellRenderer(new CustomRangeRenderer());
                tableView.table.render();
            });
        }
    }    
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;test.css&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.tooltip-inner { max-width: 400px;
text-align: left;
font-size: 14px;
font-weight: normal;
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 07:14:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Javascript-tooltip-showing-results-of-a-CSV-lookup/m-p/410441#M118418</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-02-28T07:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript tooltip showing results of a CSV lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Javascript-tooltip-showing-results-of-a-CSV-lookup/m-p/410442#M118419</link>
      <description>&lt;P&gt;Brilliant @kamlesh_vaghela that did the trick.&lt;/P&gt;

&lt;P&gt;For reference here's my search query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var searchQuery = '| makeresults | eval status ="'+cell.value+'" | lookup cim_http_status_lookup status as status OUTPUT status_description as stat_desc | table stat_desc'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thank you very much!&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 08:40:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Javascript-tooltip-showing-results-of-a-CSV-lookup/m-p/410442#M118419</guid>
      <dc:creator>alai</dc:creator>
      <dc:date>2019-02-28T08:40:08Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript tooltip showing results of a CSV lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Javascript-tooltip-showing-results-of-a-CSV-lookup/m-p/410443#M118420</link>
      <description>&lt;P&gt;@alai&lt;BR /&gt;
Glad to help you.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Happy Splunking&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 09:07:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Javascript-tooltip-showing-results-of-a-CSV-lookup/m-p/410443#M118420</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-02-28T09:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript tooltip showing results of a CSV lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Javascript-tooltip-showing-results-of-a-CSV-lookup/m-p/410444#M118421</link>
      <description>&lt;P&gt;Hey &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/127939"&gt;@kamlesh_vaghela&lt;/a&gt;, I tried your code and it works fine, but do you know why &lt;CODE&gt;"top,auto"&lt;/CODE&gt; for &lt;CODE&gt;data-placement&lt;/CODE&gt; doesn't work properly. I see it works fine outside the Splunk but when I use the JS with dashboard it doesn't work. &lt;BR /&gt;
The working example outside the Splunk dashboard: &lt;A href="https://www.w3schools.com/bootstrap/bootstrap_tooltip.asp" target="_blank"&gt;https://www.w3schools.com/bootstrap/bootstrap_tooltip.asp&lt;/A&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:35:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Javascript-tooltip-showing-results-of-a-CSV-lookup/m-p/410444#M118421</guid>
      <dc:creator>ss026381</dc:creator>
      <dc:date>2020-09-29T23:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript tooltip showing results of a CSV lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Javascript-tooltip-showing-results-of-a-CSV-lookup/m-p/410445#M118422</link>
      <description>&lt;P&gt;@ss026381 &lt;/P&gt;

&lt;P&gt;Apology for the late reply. Can you please share your code?? Please mask your original values with dummy.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 07:01:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Javascript-tooltip-showing-results-of-a-CSV-lookup/m-p/410445#M118422</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-03-14T07:01:51Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript tooltip showing results of a CSV lookup</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Javascript-tooltip-showing-results-of-a-CSV-lookup/m-p/410446#M118423</link>
      <description>&lt;P&gt;This is the js file, I am enabling tooltip on columns starts with &lt;CODE&gt;list of&lt;/CODE&gt; and for all tables that ends with &lt;CODE&gt;with_tooltip&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require([
    'underscore',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/tableview',
    'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView) {

    var CustomTooltipRenderer = TableView.BaseCellRenderer.extend({
        canRender: function(cell) {
            var re = /list\s*of.*/i;
            var result = cell.field.match(re);
            if(result){
                return cell.field;
            }
            return
        },
        render: function($td, cell) {

            var message = cell.value;
            var tip = cell.value;
            if(message.length &amp;gt; 15) { message = message.substring(0,14) + "..."
            $td.html(_.template('&amp;lt;a href="#" data-toggle="tooltip" data-placement="left auto" title="&amp;lt;%- tip%&amp;gt;"&amp;gt;&amp;lt;%- message%&amp;gt;&amp;lt;/a&amp;gt;', {
                tip: tip,
                message: message
            }));

            $td.children('[data-toggle="tooltip"]').tooltip();
            }
            else{
                $td.html(_.template(message, {
                tip: tip,
                message: message
            }));
            }
        }
    });

    var tableIDs = [];
    var domeElements = document.getElementsByTagName("div");
    for(var i=0;i&amp;lt;domeElements.length;i++)
    {
        if(domeElements[i].id != "undefined" &amp;amp;&amp;amp; domeElements[i].id.match(/.*with_tooltip$/i)){
            tableIDs.push(domeElements[i].id);
        }
    }
    for(i = 0; i &amp;lt; tableIDs.length; i++){
        mvc.Components.get(tableIDs[i]).getVisualization(function(tableView) {
            tableView.table.addCellRenderer(new CustomTooltipRenderer());
            tableView.table.render();
        });
    }
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It shows something like this,  My guess is it's missing some of bootstrap libraries or I am doing something wrong.&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://i.imgur.com/hLSnBPW.png" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 13:30:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Javascript-tooltip-showing-results-of-a-CSV-lookup/m-p/410446#M118423</guid>
      <dc:creator>ss026381</dc:creator>
      <dc:date>2019-03-14T13:30:09Z</dc:date>
    </item>
  </channel>
</rss>

