<?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 How do I add a listener to an HTML button that was added to a Splunk table viz using JavaScript? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-a-listener-to-an-HTML-button-that-was-added-to-a/m-p/573973#M47086</link>
    <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;My objective is to be able to use JavaScript to overlay buttons onto a Splunk table viz, listen for a click, and then do something upon clicking.&amp;nbsp; I've managed to overlay the buttons but I'm not sure how to listen for a click.&amp;nbsp; If I add buttons to the dashboard via an html tag then it seems that the listener gets added automatically.&amp;nbsp; Below is a run anywhere dashboard + JavaScript containing:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;An HTML table with two buttons added to the cells in dashboard XML&lt;/LI&gt;&lt;LI&gt;A Splunk table with two buttons added to the cells using JavaScript&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;All buttons have been assigned the class "html_button".&amp;nbsp; The click listener that I associated to the "html_button" class only works with the HTML table.&lt;/P&gt;&lt;P&gt;How do I add a listener to the JavaScript overlay buttons?&lt;/P&gt;&lt;P&gt;Thank you and best regards,&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;&lt;P&gt;---------------------------------------&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Dashboard&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;dashboard script="overlayTable.js"&amp;gt;
  &amp;lt;label&amp;gt;Buttons and Listeners&amp;lt;/label&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;title&amp;gt;Buttons added to HTML table&amp;lt;/title&amp;gt;
      &amp;lt;html&amp;gt;
          &amp;lt;table&amp;gt;
            &amp;lt;tr&amp;gt;
              &amp;lt;th&amp;gt;Button&amp;lt;/th&amp;gt;
            &amp;lt;/tr&amp;gt;
            &amp;lt;tr&amp;gt;
              &amp;lt;td&amp;gt;
              &amp;lt;button type="button" class="html_button"&amp;gt;x&amp;lt;/button&amp;gt;
            &amp;lt;/td&amp;gt;
            &amp;lt;/tr&amp;gt;
            &amp;lt;tr&amp;gt;
              &amp;lt;td&amp;gt;
              &amp;lt;button type="button" class="html_button"&amp;gt;x&amp;lt;/button&amp;gt;
            &amp;lt;/td&amp;gt;
            &amp;lt;/tr&amp;gt;
          &amp;lt;/table&amp;gt;
      &amp;lt;/html&amp;gt;
    &amp;lt;/panel&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;title&amp;gt;Buttons added to Splunk table using Javascript overlay&amp;lt;/title&amp;gt;
      &amp;lt;table id="tableVizualization"&amp;gt;
        &amp;lt;search id="searchObject"&amp;gt;
          &amp;lt;query&amp;gt;| makeresults 
|  eval Button = "x"
          | append [| makeresults 
    | eval Button = "x"]
          | table Button&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;0&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;20&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;none&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;/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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;overlayTable.js&lt;/STRONG&gt;&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) {

     // Add overlay buttons to table
     var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
         canRender: function(cell) {
             return _(["Button"]).contains(cell.field);
         },
         render: function($td, cell) {
            var strCellValue = cell.value;

             if (cell.field === "Button") {
                var strHtmlInput="&amp;lt;button type='button' class='html_button'&amp;gt;x&amp;lt;/button&amp;gt;"
                $td.append(strHtmlInput);
             }
         }
     });

    // Render table
     mvc.Components.get('tableVizualization').getVisualization(function(tableView) {
         tableView.addCellRenderer(new CustomRangeRenderer());
     });

	// Listener for html_button class
	$('.html_button').on("click", function (e) {
        alert("Button clicked!")
	});

 });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 08 Nov 2021 07:53:59 GMT</pubDate>
    <dc:creator>andrewtrobec</dc:creator>
    <dc:date>2021-11-08T07:53:59Z</dc:date>
    <item>
      <title>How do I add a listener to an HTML button that was added to a Splunk table viz using JavaScript?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-a-listener-to-an-HTML-button-that-was-added-to-a/m-p/573973#M47086</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;My objective is to be able to use JavaScript to overlay buttons onto a Splunk table viz, listen for a click, and then do something upon clicking.&amp;nbsp; I've managed to overlay the buttons but I'm not sure how to listen for a click.&amp;nbsp; If I add buttons to the dashboard via an html tag then it seems that the listener gets added automatically.&amp;nbsp; Below is a run anywhere dashboard + JavaScript containing:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;An HTML table with two buttons added to the cells in dashboard XML&lt;/LI&gt;&lt;LI&gt;A Splunk table with two buttons added to the cells using JavaScript&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;All buttons have been assigned the class "html_button".&amp;nbsp; The click listener that I associated to the "html_button" class only works with the HTML table.&lt;/P&gt;&lt;P&gt;How do I add a listener to the JavaScript overlay buttons?&lt;/P&gt;&lt;P&gt;Thank you and best regards,&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;&lt;P&gt;---------------------------------------&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Dashboard&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;dashboard script="overlayTable.js"&amp;gt;
  &amp;lt;label&amp;gt;Buttons and Listeners&amp;lt;/label&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;title&amp;gt;Buttons added to HTML table&amp;lt;/title&amp;gt;
      &amp;lt;html&amp;gt;
          &amp;lt;table&amp;gt;
            &amp;lt;tr&amp;gt;
              &amp;lt;th&amp;gt;Button&amp;lt;/th&amp;gt;
            &amp;lt;/tr&amp;gt;
            &amp;lt;tr&amp;gt;
              &amp;lt;td&amp;gt;
              &amp;lt;button type="button" class="html_button"&amp;gt;x&amp;lt;/button&amp;gt;
            &amp;lt;/td&amp;gt;
            &amp;lt;/tr&amp;gt;
            &amp;lt;tr&amp;gt;
              &amp;lt;td&amp;gt;
              &amp;lt;button type="button" class="html_button"&amp;gt;x&amp;lt;/button&amp;gt;
            &amp;lt;/td&amp;gt;
            &amp;lt;/tr&amp;gt;
          &amp;lt;/table&amp;gt;
      &amp;lt;/html&amp;gt;
    &amp;lt;/panel&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;title&amp;gt;Buttons added to Splunk table using Javascript overlay&amp;lt;/title&amp;gt;
      &amp;lt;table id="tableVizualization"&amp;gt;
        &amp;lt;search id="searchObject"&amp;gt;
          &amp;lt;query&amp;gt;| makeresults 
|  eval Button = "x"
          | append [| makeresults 
    | eval Button = "x"]
          | table Button&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;0&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;20&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;none&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;/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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;overlayTable.js&lt;/STRONG&gt;&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) {

     // Add overlay buttons to table
     var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
         canRender: function(cell) {
             return _(["Button"]).contains(cell.field);
         },
         render: function($td, cell) {
            var strCellValue = cell.value;

             if (cell.field === "Button") {
                var strHtmlInput="&amp;lt;button type='button' class='html_button'&amp;gt;x&amp;lt;/button&amp;gt;"
                $td.append(strHtmlInput);
             }
         }
     });

    // Render table
     mvc.Components.get('tableVizualization').getVisualization(function(tableView) {
         tableView.addCellRenderer(new CustomRangeRenderer());
     });

	// Listener for html_button class
	$('.html_button').on("click", function (e) {
        alert("Button clicked!")
	});

 });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Nov 2021 07:53:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-a-listener-to-an-HTML-button-that-was-added-to-a/m-p/573973#M47086</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2021-11-08T07:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add a listener to an HTML button that was added to a Splunk table viz using JavaScript?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-a-listener-to-an-HTML-button-that-was-added-to-a/m-p/573984#M47087</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/203131"&gt;@andrewtrobec&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please try this?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;require([
    'underscore',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/tableview',
    'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView) {

    // Add overlay buttons to table
    var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
        canRender: function(cell) {
            return _(["Button"]).contains(cell.field);
        },
        render: function($td, cell) {
            var strCellValue = cell.value;

            if (cell.field === "Button") {
                var strHtmlInput = "&amp;lt;button type='button' class='html_button'&amp;gt;x&amp;lt;/button&amp;gt;"
                $td.append(strHtmlInput).on("click", function(e) {
                    callLogincOnButtonClick()
                });
            }
        }
    });

    // Render table
    mvc.Components.get('tableVizualization').getVisualization(function(tableView) {
        tableView.addCellRenderer(new CustomRangeRenderer());
    });

    // Listener for html_button class
    $(document).ready(function() {
        $('.html_button').on("click", function(e) {
            callLogincOnButtonClick()
        });
    })

    function callLogincOnButtonClick() {
        console.log("Button clicked!")
    }
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this will help you.&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;BR /&gt;▄︻̷̿┻̿═━一 &amp;nbsp; &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Nov 2021 08:43:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-a-listener-to-an-HTML-button-that-was-added-to-a/m-p/573984#M47087</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2021-11-08T08:43:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add a listener to an HTML button that was added to a Splunk table viz using JavaScript?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-a-listener-to-an-HTML-button-that-was-added-to-a/m-p/574002#M47088</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/127939"&gt;@kamlesh_vaghela&lt;/a&gt;&amp;nbsp;Thank you for your reply.&amp;nbsp; I tried as suggested but this does not solve the issue.&amp;nbsp; The HTML buttons continue to work, but the JavaScript buttons do not.&amp;nbsp; Did this code work for you?&amp;nbsp; Do you have any other suggestions?&amp;nbsp; Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 08 Nov 2021 12:16:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-a-listener-to-an-HTML-button-that-was-added-to-a/m-p/574002#M47088</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2021-11-08T12:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add a listener to an HTML button that was added to a Splunk table viz using JavaScript?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-a-listener-to-an-HTML-button-that-was-added-to-a/m-p/574021#M47096</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/203131"&gt;@andrewtrobec&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes.. It is working for me. &amp;nbsp;Try this.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;function callLogincOnButtonClick() {
        alert("Button clicked!")
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Nov 2021 13:55:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-a-listener-to-an-HTML-button-that-was-added-to-a/m-p/574021#M47096</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2021-11-08T13:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do I add a listener to an HTML button that was added to a Splunk table viz using JavaScript?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-a-listener-to-an-HTML-button-that-was-added-to-a/m-p/574334#M47122</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/127939"&gt;@kamlesh_vaghela&lt;/a&gt;&amp;nbsp;Just to be sure I recopied your original post and it works!&amp;nbsp; I must have done it incorrectly, sorry for the false negative &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; Thank you so much for your support, I really appreciate i!&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 07:33:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-do-I-add-a-listener-to-an-HTML-button-that-was-added-to-a/m-p/574334#M47122</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2021-11-10T07:33:38Z</dc:date>
    </item>
  </channel>
</rss>

