<?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: How to use dynamic checkbox in Table? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-dynamic-checkbox-in-table/m-p/638612#M52222</link>
    <description>&lt;P&gt;how to pass the JSON response from JS to XML.I need to put it serach query&lt;/P&gt;&lt;PRE&gt;| eval _raw=**JSON response**&lt;/PRE&gt;</description>
    <pubDate>Tue, 04 Apr 2023 09:18:33 GMT</pubDate>
    <dc:creator>silambarasu</dc:creator>
    <dc:date>2023-04-04T09:18:33Z</dc:date>
    <item>
      <title>How to use dynamic checkbox in table?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-dynamic-checkbox-in-table/m-p/635091#M52049</link>
      <description>&lt;P&gt;I need to create customize table in splunk. can you pls help how to implement that part and also attached the&amp;nbsp; sample image.it should be like that.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="silambarasu_0-1679299901008.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/24371iF8AD765A5BDCDBE3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="silambarasu_0-1679299901008.png" alt="silambarasu_0-1679299901008.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 10:31:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-dynamic-checkbox-in-table/m-p/635091#M52049</guid>
      <dc:creator>silambarasu</dc:creator>
      <dc:date>2023-04-04T10:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to use dynamic checkbox in Table?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-dynamic-checkbox-in-table/m-p/638295#M52206</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/254925"&gt;@silambarasu&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please try this?&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;XML&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;form script="multiselect_table.js" stylesheet="multiselect_table.css"&amp;gt;
   &amp;lt;label&amp;gt;Multi-Select Table Rows Example&amp;lt;/label&amp;gt;
   &amp;lt;row&amp;gt;
     &amp;lt;panel&amp;gt;
       &amp;lt;table id="myTable"&amp;gt;
         &amp;lt;title&amp;gt;Panel A&amp;lt;/title&amp;gt;
         &amp;lt;search id="SearchA"&amp;gt;
           &amp;lt;query&amp;gt;| makeresults 
| eval _raw="{\"data\":[{\"id\":1,\"value\":\"test\"},{\"id\":2,\"value\":\"test2\"}]}" 
| rename comment as "upto now is data only" 
| spath path=data{} output=data 
| mvexpand data 
| spath input=data 
| eval CheckBox=id
| table CheckBox id value&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;row&amp;lt;/option&amp;gt;
         &amp;lt;option name="refresh.display"&amp;gt;progressbar&amp;lt;/option&amp;gt;
         &amp;lt;drilldown&amp;gt;
           &amp;lt;condition field="*"&amp;gt;&amp;lt;/condition&amp;gt;
         &amp;lt;/drilldown&amp;gt;
       &amp;lt;/table&amp;gt;
     &amp;lt;/panel&amp;gt;
     &amp;lt;panel&amp;gt;
       &amp;lt;html&amp;gt;
        &amp;lt;div&amp;gt;
          &amp;lt;input type="button" id="mybutton" value="Submit"/&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/html&amp;gt;
     &amp;lt;/panel&amp;gt;
     &amp;lt;panel&amp;gt;
       &amp;lt;table&amp;gt;
         &amp;lt;title&amp;gt;Ids Processed&amp;lt;/title&amp;gt;
         &amp;lt;search id="SearchB"&amp;gt;
           &amp;lt;query&amp;gt;| makeresults | eval SelectedRowValue="$mytoken$" | makemv delim="," SelectedRowValue | stats count by SelectedRowValue | table SelectedRowValue&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;/table&amp;gt;
     &amp;lt;/panel&amp;gt;
   &amp;lt;/row&amp;gt;
 &amp;lt;/form&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Screenshot&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2023-04-03 at 11.27.15 AM.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/24671i9EC108F223DDEEEC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2023-04-03 at 11.27.15 AM.png" alt="Screenshot 2023-04-03 at 11.27.15 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Javascript file (multiselect_table.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) {
     // Access the "default" token model
     var tokens = mvc.Components.get("default");
     var selected_values_array = [];
     var isSelectAll = false;
     var searchAValues = [];
     var searchAFields = [];
     var fieldKey = "CheckBox";
     var fieldDataStoreKey="data-sort-key="+fieldKey;
     var submittedTokens = mvc.Components.get('submitted');
     console.log("This is Multi-select table JS");
     // Custom renderer for applying checkbox.
     var CustomRenderer = TableView.BaseCellRenderer.extend({
             canRender: function (cell) {
                 return _([fieldKey]).contains(cell.field);
             },
             render: function ($td, cell) {
                 // all_values_array.push(cell.value);
                 var cls = "checkbox";
                 if(isSelectAll) {
                     cls = "checkbox checked";
                 }
                 var a = $('&amp;lt;div&amp;gt;').attr({
                     "id": "chk-sourcetype_" + cell.value,
                     "value": cell.value
                 }).addClass(cls).click(function () {
                     if ($(this).attr('class') === "checkbox") {
                         selected_values_array.push($(this).attr('value'));
                         $(this).removeClass();
                         $(this).addClass("checkbox checked");
                     } else {
                         $(this).removeClass();
                         $(this).addClass("checkbox");
                         var i = selected_values_array.indexOf($(this).attr('value'));
                         if (i != -1) {
                             selected_values_array.splice(i, 1);
                         }
                     }
                 }).appendTo($td);
             }
         });
 
     //List of table ID
     var sh = mvc.Components.get("myTable");
     if (typeof(sh) != "undefined") {
         sh.getVisualization(function (tableView) {
             // Add custom cell renderer and force re-render
             tableView.table.addCellRenderer(new CustomRenderer());
             tableView.table.render();
             tableView.on('rendered', function(view) {
                 setCheckAllCheckBox();
             });
             // setCheckAllCheckBox();
         });
     }
 
     var SearchA = mvc.Components.get("SearchA");
     var SearchAResults = SearchA.data("results");
     SearchAResults.on("data", function () {
         resultArray = SearchAResults.data().rows;
         searchAFields = SearchAResults.data().fields;
         var keyIndex=searchAFields.indexOf(fieldKey);
         searchAValues = [];
         $.each(resultArray, function (index, value) { 
             searchAValues[index]=value[keyIndex];
         })
     });
 
     SearchA.on('search:start', function (properties) {
         isSelectAll = false;
         tokens.unset("mytoken");
         tokens.set("mytoken", "");
         submittedTokens.set(tokens.toJSON());
     });
     SearchA.on('search:done', function (properties) {
         console.log("in search done",properties);
     });
 
     // Disabling button while search is running
     var SearchB = mvc.Components.get('SearchB');
     SearchB.on('search:start', function (properties) {
         $("#mybutton").attr('disabled', true);
     });
 
     SearchB.on('search:done', function (properties) {
         $("#mybutton").attr('disabled', false);
     });
     var sto;
     function setCheckAllCheckBox()
     {
         var a = $("["+fieldDataStoreKey+"]");
         a.html("");
         var cls = "checkbox";
         if(isSelectAll) {
             cls = "checkbox checked";
         }
         var temp = $('&amp;lt;div&amp;gt;').attr({
             "id": "chk-sourcetype-All",
             "value": "All"
         }).addClass(cls).click(function () {
             if ($(this).attr('class') === "checkbox") {
                 $(this).removeClass();
                 $(this).addClass("checkbox checked");
                 isSelectAll = true;
             } else {
                 $(this).removeClass();
                 $(this).addClass("checkbox");
                 isSelectAll = false;
             }
             checkUnCheckAllCheckboxes();
         }).appendTo(a);
         $("["+fieldDataStoreKey+"]").parent().removeAttr("class");
         $("["+fieldDataStoreKey+"]").removeAttr("data-sort-key");
     }
     function checkUnCheckAllCheckboxes(){
         var cls = "checkbox";
         selected_values_array = [];
         if(isSelectAll) {
             cls = "checkbox checked";
             $.each(searchAValues, function (index, value) { 
                 selected_values_array.push(value);
             })
         }
         $('[id^="chk-sourcetype_"]').removeClass();
         $('[id^="chk-sourcetype_"]').addClass(cls);
     }

     function updateDataOnServerSide() {
        var service = mvc.createService({ owner: "nobody" });
        //send data to server
        console.log(selected_values_array.join());
        var params = selected_values_array.join();
        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
            }
          });
     }
     
     $(document).ready(function () {
         //setting up tokens with selected value.
         $("#mybutton").on("click", function (e) {
             e.preventDefault();
             updateDataOnServerSide();
             tokens.set("mytoken", selected_values_array.join());
             submittedTokens.set(tokens.toJSON());
             $("#mybutton").attr('disabled', true);
         });
         // setCheckAllCheckBox();
         setTimeout(function(){
             setCheckAllCheckBox();
         },2000);
     });
 });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;CSS (multiselect_table.css)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="css"&gt;/* The standalone checkbox square*/
 .checkbox {
   width:20px;
   height:20px;
   border: 1px solid #000;
   display: inline-block;
 }
 
 /* This is what simulates a checkmark icon */
 .checkbox.checked:after {
   content: '';
   display: block;
   width: 4px;
   height: 7px;
   
   /* "Center" the checkmark */
   position:relative;
   top:4px;
   left:7px;
   
   border: solid #000;
   border-width: 0 2px 2px 0;
   transform: rotate(45deg);
 }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Note:&lt;/STRONG&gt; Up to now is just a reference code, just copy and paste.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The next steps:&lt;/STRONG&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Follow the below link and create a server-side logic by creating a custom endpoint in Splunk.&lt;OL&gt;&lt;LI&gt;&lt;A href="https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-Javascript-for-a-button-on-a-splunk-dashboard/m-p/627631#M51435" target="_blank"&gt;https://community.splunk.com/t5/Dashboards-Visualizations/How-to-create-Javascript-for-a-button-on-a-splunk-dashboard/m-p/627631#M51435&lt;/A&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Then Execute the custom API from the dashboard. &lt;/SPAN&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN&gt;You need to update the API path in&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;STRONG&gt;updateDataOnServerSide&lt;/STRONG&gt;&amp;nbsp;function&amp;nbsp;in&amp;nbsp;&lt;STRONG&gt;multiselect_table.js&amp;nbsp;&lt;/STRONG&gt;file.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;You can also handle the HTTP errors in dashboard UI as well.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;&amp;nbsp;You need to change the search query in the dashboard by providing your index and source type also.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I hope this will help you.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&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;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2023 05:59:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-dynamic-checkbox-in-table/m-p/638295#M52206</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2023-04-03T05:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to use dynamic checkbox in Table?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-dynamic-checkbox-in-table/m-p/638304#M52208</link>
      <description>&lt;P&gt;it's working as expected... Thnks Kamlesh&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2023 06:36:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-dynamic-checkbox-in-table/m-p/638304#M52208</guid>
      <dc:creator>silambarasu</dc:creator>
      <dc:date>2023-04-03T06:36:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to use dynamic checkbox in Table?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-dynamic-checkbox-in-table/m-p/638612#M52222</link>
      <description>&lt;P&gt;how to pass the JSON response from JS to XML.I need to put it serach query&lt;/P&gt;&lt;PRE&gt;| eval _raw=**JSON response**&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Apr 2023 09:18:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-dynamic-checkbox-in-table/m-p/638612#M52222</guid>
      <dc:creator>silambarasu</dc:creator>
      <dc:date>2023-04-04T09:18:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to use dynamic checkbox in Table?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-dynamic-checkbox-in-table/m-p/638622#M52224</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/254925"&gt;@silambarasu&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just set a token in JS and use it in XML. take a reference of mytoken in above code.&lt;/P&gt;&lt;P&gt;KV&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 10:12:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-use-dynamic-checkbox-in-table/m-p/638622#M52224</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2023-04-04T10:12:33Z</dc:date>
    </item>
  </channel>
</rss>

