<?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 select table row values in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-select-table-row-values/m-p/377368#M24690</link>
    <description>&lt;P&gt;Awesome!!! Thank you a lot!!!&lt;/P&gt;</description>
    <pubDate>Thu, 23 May 2019 08:14:33 GMT</pubDate>
    <dc:creator>dreadangel</dc:creator>
    <dc:date>2019-05-23T08:14:33Z</dc:date>
    <item>
      <title>Javascript select table row values</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-select-table-row-values/m-p/377365#M24687</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;

&lt;P&gt;How would I select an entire row in a table from a dashboard and use each field/cell from that table to populate another panel/table when selected? Essentially just cloning whatever rows i select from one panel -&amp;gt; hit submit -&amp;gt; selected rows go to another panel.&lt;/P&gt;

&lt;P&gt;Any thoughts on how to achieve this?&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2019 12:59:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-select-table-row-values/m-p/377365#M24687</guid>
      <dc:creator>mwdbhyat</dc:creator>
      <dc:date>2019-05-17T12:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript select table row values</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-select-table-row-values/m-p/377366#M24688</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/180565"&gt;@mwdbhyat&lt;/a&gt; &lt;/P&gt;

&lt;P&gt;You are lucky. I'm working on the same for another purpose but I'm sure you will achieve the same by using the below code.&lt;/P&gt;

&lt;P&gt;Note: This code is now Specific to &lt;CODE&gt;index=_internal | stats count by sourcetype | eval recNumber=1 | accum recNumber | table recNumber sourcetype count&lt;/CODE&gt; - this - search. So you have to manual change for your search.  In your search you have to add &lt;CODE&gt;| eval recNumber=1 | accum recNumber&lt;/CODE&gt; and put this as checkbox column.  find &lt;CODE&gt;recNumber&lt;/CODE&gt; in javascript which will let you know at how many places you have to make changes.  Another field is &lt;CODE&gt;sourcetype&lt;/CODE&gt;, this will also help you.&lt;/P&gt;

&lt;P&gt;XML&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard script="multiselect_table_data.js" stylesheet="multiselect_table_data.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="myPrimarySearch"&amp;gt;
          &amp;lt;query&amp;gt;index=_internal | stats count by sourcetype | eval recNumber=1 | accum recNumber | table recNumber sourcetype count&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 id="secondTable"&amp;gt;
        &amp;lt;title&amp;gt;Panel B&amp;lt;/title&amp;gt;
        &amp;lt;search id="mysearch"&amp;gt;
          &amp;lt;query&amp;gt; $searchQuery$ &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;/dashboard&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;multiselect_table_data.js&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;require([
        'underscore',
        'jquery',
        'splunkjs/mvc',
        'splunkjs/mvc/tableview',
        'splunkjs/mvc/simplexml/ready!'
    ], function (_, $, mvc, TableView) {
    // Access the "default" token model

    var defaultTokenModel = mvc.Components.get("default");
    var selected_values_array = [];
    var submittedTokens = mvc.Components.get('submitted');

    var myPrimarySearchData;

    var myPrimarySearch = mvc.Components.get('myPrimarySearch');
    var myPrimarySearch_results = myPrimarySearch.data("preview");
    //console.log("myPrimarySearch_results",myPrimarySearch_results);


    var myPrimarySearchArray = [];
    myPrimarySearch_results.on("data", function() {
        myPrimarySearchData = myPrimarySearch_results.data();

    });


    console.log("This is Multi-select table JS");
    // Custom renderer for applying checkbox.
    var FirstTableRenderer = TableView.BaseCellRenderer.extend({
        canRender: function (cell) {
            return _(['recNumber']).contains(cell.field);
        },
        render: function ($td, cell) {
            var a = $('&amp;lt;div&amp;gt;').attr({
                    "id": "chk-sourcetype" + cell.value,
                    "value": cell.value
                }).addClass('checkbox').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);
                        }
                    }
                });
                if(selected_values_array.indexOf(cell.value) &amp;gt; -1) {
                    a = a.addClass("checked");
                }
                a.appendTo($td);
        }
    });

    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 FirstTableRenderer());
            tableView.table.render();
        });
    }

    // Disabling button while search is running 
    var mysearch = mvc.Components.get('mysearch');
    mysearch.on('search:start', function (properties) {
        $("#mybutton").attr('disabled', true);
    });

    mysearch.on('search:done', function (properties) {
        $("#mybutton").attr('disabled', false);
    });

    $(document).ready(function () {
        //setting up tokens with selected value.
        $("#mybutton").on("click", function (e) {
            e.preventDefault();
            setArrayInToken();
        });
    });

    function setArrayInToken(){
        defaultTokenModel.set("mytoken", selected_values_array.join());
        submittedTokens.set(defaultTokenModel.toJSON());
    }

    defaultTokenModel.on("change:mytoken", function(formQuery, indexName) {
        var newQuery = ' | makeresults | eval recNumber="'+indexName+'" | makemv delim="," recNumber | stats count by recNumber  | eval sourcetype=recNumber,count=recNumber | table  sourcetype count';
        console.log(newQuery);
        defaultTokenModel.set('searchQuery', newQuery);
    });

    var SecondTableRenderer = TableView.BaseCellRenderer.extend({
        canRender: function (cell) {
            return _(['recNumber','sourcetype','count']).contains(cell.field);
        },
        render: function ($td, cell) {
            var rows = myPrimarySearchData.rows;
            var fields = myPrimarySearchData.fields;
            var dataIndex = fields.indexOf(cell.field);
            var cellValue=rows[cell.value - 1][dataIndex];
            $td.addClass("string");
            var a = $('&amp;lt;div&amp;gt;'+cellValue+'&amp;lt;/div&amp;gt;').appendTo($td);            
        }
    });

    var sh = mvc.Components.get("secondTable");
    if (typeof(sh) != "undefined") {
        sh.getVisualization(function (tableView) {
            // Add custom cell renderer and force re-render
            tableView.table.addCellRenderer(new SecondTableRenderer());
            tableView.table.render();
        });
    }   
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;multiselect_table_data.css&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&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;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Sep 2020 00:32:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-select-table-row-values/m-p/377366#M24688</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2020-09-30T00:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript select table row values</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-select-table-row-values/m-p/377367#M24689</link>
      <description>&lt;P&gt;@kamlesh_vaghela awesome stuff this is really cool! Thanks! Do you have any tricks up your sleeve to send a sparkline across from table 1 to table 2 =D ..i have some timechart sparkline graphs in table 1 and in table 2 they are just the numerical values.. &lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2019 16:24:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-select-table-row-values/m-p/377367#M24689</guid>
      <dc:creator>mwdbhyat</dc:creator>
      <dc:date>2019-05-17T16:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript select table row values</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-select-table-row-values/m-p/377368#M24690</link>
      <description>&lt;P&gt;Awesome!!! Thank you a lot!!!&lt;/P&gt;</description>
      <pubDate>Thu, 23 May 2019 08:14:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-select-table-row-values/m-p/377368#M24690</guid>
      <dc:creator>dreadangel</dc:creator>
      <dc:date>2019-05-23T08:14:33Z</dc:date>
    </item>
  </channel>
</rss>

