<?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 to add dropdown and button in Splunk table cells? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-add-dropdown-and-button-in-Splunk-table-cells/m-p/647508#M52942</link>
    <description>&lt;P&gt;I have a splunk table where there are few columns having dropdown (eg ddcol1, ddcol2 ) and at last there is a column having button(submit)&lt;/P&gt;
&lt;P&gt;The functionality of the button is to mark all the dropdowns with a default value(ok)&lt;/P&gt;
&lt;P&gt;I have written the below js , but the dropdown doesnt update on click of the button&amp;nbsp;&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 dropdown to table
    var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
        canRender: function(cell) {
            return _(["ddcol1","ddcol2","submit"]).contains(cell.field);
        },
        render: function($td, cell) {
            console.log(cell.field);
            if (cell.field == "ddcol1" || cell.field == "ddcol2") {
                if(cell.value == "dd") {
                    var strHtmlInput = `
                        &amp;lt;select&amp;gt;
                            &amp;lt;option value="ok"&amp;gt;ok&amp;lt;/option&amp;gt;
                            &amp;lt;option value="not ok"&amp;gt;Not Ok&amp;lt;/option&amp;gt;
                        &amp;lt;/select&amp;gt;
                        `;
                    $td.append(strHtmlInput).on("change", function(e) {
                        console.log(e.target.value)
                    });
                }
                else {
                    $td.append(cell.value);
                }
            }
            if (cell.field == "submit"){
                console.log(cell.field);
                var strHtmlInput1=`&amp;lt;input type='button' class='table-button' value='All Ok'&amp;gt;&amp;lt;/input&amp;gt;`;
                $td.append(strHtmlInput1);
            }
        }
});
   $(document).on("click",".table-button",function(){
           console.log("clicked");
           console.log($(this).parents("tr").find("td[data-cell-index='6'").find(":selected").text());
           $(this).parents("tr").find("td[data-cell-index='6']").find(":selected").value="ok";
           console.log('selected');
           console.log($(this).parents("tr").find("td[data-cell-index='6'").find(":selected").text());

   });

    var sh = mvc.Components.get("tbl1");
    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;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/201110"&gt;@niketn&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/127939"&gt;@kamlesh_vaghela&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Jun 2023 02:23:53 GMT</pubDate>
    <dc:creator>Jitu</dc:creator>
    <dc:date>2023-06-20T02:23:53Z</dc:date>
    <item>
      <title>How to add dropdown and button in Splunk table cells?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-add-dropdown-and-button-in-Splunk-table-cells/m-p/647508#M52942</link>
      <description>&lt;P&gt;I have a splunk table where there are few columns having dropdown (eg ddcol1, ddcol2 ) and at last there is a column having button(submit)&lt;/P&gt;
&lt;P&gt;The functionality of the button is to mark all the dropdowns with a default value(ok)&lt;/P&gt;
&lt;P&gt;I have written the below js , but the dropdown doesnt update on click of the button&amp;nbsp;&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 dropdown to table
    var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
        canRender: function(cell) {
            return _(["ddcol1","ddcol2","submit"]).contains(cell.field);
        },
        render: function($td, cell) {
            console.log(cell.field);
            if (cell.field == "ddcol1" || cell.field == "ddcol2") {
                if(cell.value == "dd") {
                    var strHtmlInput = `
                        &amp;lt;select&amp;gt;
                            &amp;lt;option value="ok"&amp;gt;ok&amp;lt;/option&amp;gt;
                            &amp;lt;option value="not ok"&amp;gt;Not Ok&amp;lt;/option&amp;gt;
                        &amp;lt;/select&amp;gt;
                        `;
                    $td.append(strHtmlInput).on("change", function(e) {
                        console.log(e.target.value)
                    });
                }
                else {
                    $td.append(cell.value);
                }
            }
            if (cell.field == "submit"){
                console.log(cell.field);
                var strHtmlInput1=`&amp;lt;input type='button' class='table-button' value='All Ok'&amp;gt;&amp;lt;/input&amp;gt;`;
                $td.append(strHtmlInput1);
            }
        }
});
   $(document).on("click",".table-button",function(){
           console.log("clicked");
           console.log($(this).parents("tr").find("td[data-cell-index='6'").find(":selected").text());
           $(this).parents("tr").find("td[data-cell-index='6']").find(":selected").value="ok";
           console.log('selected');
           console.log($(this).parents("tr").find("td[data-cell-index='6'").find(":selected").text());

   });

    var sh = mvc.Components.get("tbl1");
    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;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/201110"&gt;@niketn&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/127939"&gt;@kamlesh_vaghela&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2023 02:23:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-add-dropdown-and-button-in-Splunk-table-cells/m-p/647508#M52942</guid>
      <dc:creator>Jitu</dc:creator>
      <dc:date>2023-06-20T02:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to add dropdown and button in Splunk table cells?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-add-dropdown-and-button-in-Splunk-table-cells/m-p/647703#M52976</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/224436"&gt;@Jitu&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Update button onclick logic with below.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;    $(document).on("click", ".table-button", function () {
        var parentElement = $(this).parents("tr");
        console.log(parentElement);
        var selectElements = parentElement.find('select');
        console.log(selectElements);
        selectElements.each(function () {
            $(this).val('ok');
        });

    });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Full Code:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;XML&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;dashboard script="my.js"&amp;gt;
  &amp;lt;label&amp;gt;Table With Component&amp;lt;/label&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;table id="tbl1"&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;| makeresults count=10 | eval a=1 | accum a | eval ddcol1="dd" ,ddcol2="dd",submit="submit"&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;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="percentagesRow"&amp;gt;false&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;my.js&lt;/STRONG&gt;&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 dropdown to table
    var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
        canRender: function (cell) {
            return _(["ddcol1", "ddcol2", "submit"]).contains(cell.field);
        },
        render: function ($td, cell) {
            console.log(cell.field);
            if (cell.field == "ddcol1" || cell.field == "ddcol2") {
                if (cell.value == "dd") {
                    var strHtmlInput = `
                        &amp;lt;select&amp;gt;
                            &amp;lt;option value="ok"&amp;gt;ok&amp;lt;/option&amp;gt;
                            &amp;lt;option value="not ok"&amp;gt;Not Ok&amp;lt;/option&amp;gt;
                        &amp;lt;/select&amp;gt;
                        `;
                    $td.append(strHtmlInput).on("change", function (e) {
                        console.log(e.target.value)
                    });
                }
                else {
                    $td.append(cell.value);
                }
            }
            if (cell.field == "submit") {
                console.log(cell.field);
                var strHtmlInput1 = `&amp;lt;input type='button' class='table-button' value='All Ok'&amp;gt;&amp;lt;/input&amp;gt;`;
                $td.append(strHtmlInput1);
            }
        }
    });
    $(document).on("click", ".table-button", function () {
        var parentElement = $(this).parents("tr");
        console.log(parentElement);
        var selectElements = parentElement.find('select');
        console.log(selectElements);
        selectElements.each(function () {
            $(this).val('ok');
        });

    });

    var sh = mvc.Components.get("tbl1");
    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;/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;If any of my replies help you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jun 2023 05:39:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-add-dropdown-and-button-in-Splunk-table-cells/m-p/647703#M52976</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2023-06-21T05:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to add dropdown and button in Splunk table cells?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-add-dropdown-and-button-in-Splunk-table-cells/m-p/647903#M52998</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;if i need a button to upload the table result to summary along with dropdown selection , is it possible ?&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2023 11:40:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-add-dropdown-and-button-in-Splunk-table-cells/m-p/647903#M52998</guid>
      <dc:creator>Jitu</dc:creator>
      <dc:date>2023-06-22T11:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to add dropdown and button in Splunk table cells?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-add-dropdown-and-button-in-Splunk-table-cells/m-p/647981#M53011</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/224436"&gt;@Jitu&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, you can. But for this, you have to create a custom endpoint that can process your table data sent through payload. Please check the below link for the custom endpoint. You need to call this endpoint from JavaScript using the Splunk MVC Service object.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://hurricanelabs.com/splunk-tutorials/splunk-custom-endpoints-part-1-the-basics/" target="_blank"&gt;https://hurricanelabs.com/splunk-tutorials/splunk-custom-endpoints-part-1-the-basics/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Sample Code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;service.request("/services/my-api-path","POST", {}, {}, JSON.stringify(params), {'Content-Type': 'application/json'}, function(err, resp) {
         // Handle response    
         if(resp != null){
           if(resp.status == 200){  
             //do something
           } else {
             //do something with status !=200
           }
         }
         // Handle error
         if(err != null){
           //handle error
         }
       });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I hope this will help you.&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;BR /&gt;If any of my replies help you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2023 16:58:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-add-dropdown-and-button-in-Splunk-table-cells/m-p/647981#M53011</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2023-06-22T16:58:29Z</dc:date>
    </item>
  </channel>
</rss>

