<?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 Why is Javascript not running until I click on &amp;quot;Edit&amp;quot; , and it runs twice after that? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-Javascript-not-running-until-I-click-on-quot-Edit-quot/m-p/437479#M41228</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;My Javascript is supposed to create a table with values, however it is not showing any results until I click on the "Edit" button then "Cancel".&lt;/P&gt;

&lt;P&gt;The results will only show after I have done the steps above, however, the JS runs twice instead of once, which is seen by the repeated result values shown twice on my dashboard.&lt;/P&gt;

&lt;P&gt;Below is my javascript code for reference:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    require(['splunkjs/ready!'], function () {
        require([
            'underscore',
            'jquery',
            'splunkjs/mvc',
            'splunkjs/mvc/tableview',
            'splunkjs/mvc/simplexml/ready!'
        ], function (_, $, mvc, TableView) {    
                var table_detail = [];
                var i = 0;
                //var j = 3;
                var k = 0;
                var a = 0; 

                var RangeMapIconRenderer = TableView.BaseCellRenderer.extend({
                    canRender: function (cell) {
                        // Only use the cell renderer for the range field
                        return _(['detail']).contains(cell.field);

                        //return cell.field === 'order_number';
                    },
                    render: function ($td, cell) {

                        /*
                        //newly added
                        if (currentRow &amp;lt; totalResults) {
                                currentRow++;
                        } else if (currentRow == totalResults) {
                            currentRow++;
                        */
                            if (cell.field == 'detail'){
                                console.log("yes it's detail table1");
                                //for (i; i&amp;lt;table_detail.length; i++){                            
                                var temp=[];
                                var j = 5;
                                temp = cell.value.split(',');        

                                if(temp[j] == 'ALL GREEN'){
                                    console.log("came into IF statement, going in loop");
                                        var parenttbl = document.getElementById("listdetail_0");
                                        var newtr = document.createElement('tr');  
                                        var newtd = document.createElement('td'); 

                                        newtd.setAttribute('class',"ok-all");
                                        newtd.setAttribute('align',"center");
                                        newtd.setAttribute('id',"newtd" +a);

                                        newtr.appendChild(newtd);
                                        parenttbl.appendChild(newtr);


                                        document.getElementById('newtd'+a).innerHTML = temp[j];

                                        a++;
                                }
                                else{    
                                    console.log("came into else statement, going in loop");

                                    for (j; j&amp;lt;(temp.length-1); j+=2){ 
                                        var parenttbl = document.getElementById("listdetail_0");
                                        var newtr = document.createElement('tr');  
                                        var newtr1 = document.createElement('tr');
                                        var newel = document.createElement('td'); 
                                        newtr1.setAttribute('id',"rowtr"+a);                       
                                        newel.setAttribute('class',"pad-0");
                                        //document.getElementById("col"+i).classList.add('pad-0');
                                        var newDiv = document.createElement('div');
                                        newDiv.setAttribute('id',"list_item_"+a);
                                        newDiv.setAttribute('class',"list-table");
                                        //document.getElementById("list_item_"+a).classList.add('list-table');
                                        var newDivIcon = document.createElement('div');
                                        k = j+1;
                                        newDivIcon.setAttribute('id',"icon_"+a);
                                        newDivIcon.setAttribute('class',temp[k] +"-img");
                                        //document.getElementById('icon_'+a).className = temp[k] +"-img";
                                        newel.appendChild(newDiv);
                                        newel.appendChild(newDivIcon);
                                        newtr.appendChild(newel);
                                        parenttbl.appendChild(newtr);
                                        parenttbl.appendChild(newtr1);
                                        document.getElementById('list_item_'+a).innerHTML = temp[j];

                                        //add separator                        
                                        document.getElementById("rowtr"+a).innerHTML='&amp;lt;td&amp;gt;&amp;lt;div class="separators" style="padding-left: 10%"&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/td&amp;gt;';
                                        a++;
                                    }
                                }

                                document.getElementById('last_update_0').innerHTML = temp[(temp.length-1)];    
                                i++;                   
                                //} 
                                //table_detail.push(cell.value);
                                console.log(cell.value);    
                            }       
                        //}      
                    }
                });    

                const tableIds = ['detailMajor'];
                var totalResults = 0;
                var currentRow = 0;
                var interval = 1;

                tableIds.forEach((ID) =&amp;gt; {
                        mvc.Components.get(ID).getVisualization(function (tableView) {
                                // Register custom cell renderer, the table will re-render automatically
                                totalResults = 1;
                                tableView.addCellRenderer(new RangeMapIconRenderer());
                        });
                })
        });       
    });     
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Will really appreciate any help regarding this issue. &lt;/P&gt;

&lt;P&gt;Thank you!&lt;/P&gt;</description>
    <pubDate>Fri, 13 Jul 2018 10:33:16 GMT</pubDate>
    <dc:creator>pinggg</dc:creator>
    <dc:date>2018-07-13T10:33:16Z</dc:date>
    <item>
      <title>Why is Javascript not running until I click on "Edit" , and it runs twice after that?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-Javascript-not-running-until-I-click-on-quot-Edit-quot/m-p/437479#M41228</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;My Javascript is supposed to create a table with values, however it is not showing any results until I click on the "Edit" button then "Cancel".&lt;/P&gt;

&lt;P&gt;The results will only show after I have done the steps above, however, the JS runs twice instead of once, which is seen by the repeated result values shown twice on my dashboard.&lt;/P&gt;

&lt;P&gt;Below is my javascript code for reference:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    require(['splunkjs/ready!'], function () {
        require([
            'underscore',
            'jquery',
            'splunkjs/mvc',
            'splunkjs/mvc/tableview',
            'splunkjs/mvc/simplexml/ready!'
        ], function (_, $, mvc, TableView) {    
                var table_detail = [];
                var i = 0;
                //var j = 3;
                var k = 0;
                var a = 0; 

                var RangeMapIconRenderer = TableView.BaseCellRenderer.extend({
                    canRender: function (cell) {
                        // Only use the cell renderer for the range field
                        return _(['detail']).contains(cell.field);

                        //return cell.field === 'order_number';
                    },
                    render: function ($td, cell) {

                        /*
                        //newly added
                        if (currentRow &amp;lt; totalResults) {
                                currentRow++;
                        } else if (currentRow == totalResults) {
                            currentRow++;
                        */
                            if (cell.field == 'detail'){
                                console.log("yes it's detail table1");
                                //for (i; i&amp;lt;table_detail.length; i++){                            
                                var temp=[];
                                var j = 5;
                                temp = cell.value.split(',');        

                                if(temp[j] == 'ALL GREEN'){
                                    console.log("came into IF statement, going in loop");
                                        var parenttbl = document.getElementById("listdetail_0");
                                        var newtr = document.createElement('tr');  
                                        var newtd = document.createElement('td'); 

                                        newtd.setAttribute('class',"ok-all");
                                        newtd.setAttribute('align',"center");
                                        newtd.setAttribute('id',"newtd" +a);

                                        newtr.appendChild(newtd);
                                        parenttbl.appendChild(newtr);


                                        document.getElementById('newtd'+a).innerHTML = temp[j];

                                        a++;
                                }
                                else{    
                                    console.log("came into else statement, going in loop");

                                    for (j; j&amp;lt;(temp.length-1); j+=2){ 
                                        var parenttbl = document.getElementById("listdetail_0");
                                        var newtr = document.createElement('tr');  
                                        var newtr1 = document.createElement('tr');
                                        var newel = document.createElement('td'); 
                                        newtr1.setAttribute('id',"rowtr"+a);                       
                                        newel.setAttribute('class',"pad-0");
                                        //document.getElementById("col"+i).classList.add('pad-0');
                                        var newDiv = document.createElement('div');
                                        newDiv.setAttribute('id',"list_item_"+a);
                                        newDiv.setAttribute('class',"list-table");
                                        //document.getElementById("list_item_"+a).classList.add('list-table');
                                        var newDivIcon = document.createElement('div');
                                        k = j+1;
                                        newDivIcon.setAttribute('id',"icon_"+a);
                                        newDivIcon.setAttribute('class',temp[k] +"-img");
                                        //document.getElementById('icon_'+a).className = temp[k] +"-img";
                                        newel.appendChild(newDiv);
                                        newel.appendChild(newDivIcon);
                                        newtr.appendChild(newel);
                                        parenttbl.appendChild(newtr);
                                        parenttbl.appendChild(newtr1);
                                        document.getElementById('list_item_'+a).innerHTML = temp[j];

                                        //add separator                        
                                        document.getElementById("rowtr"+a).innerHTML='&amp;lt;td&amp;gt;&amp;lt;div class="separators" style="padding-left: 10%"&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/td&amp;gt;';
                                        a++;
                                    }
                                }

                                document.getElementById('last_update_0').innerHTML = temp[(temp.length-1)];    
                                i++;                   
                                //} 
                                //table_detail.push(cell.value);
                                console.log(cell.value);    
                            }       
                        //}      
                    }
                });    

                const tableIds = ['detailMajor'];
                var totalResults = 0;
                var currentRow = 0;
                var interval = 1;

                tableIds.forEach((ID) =&amp;gt; {
                        mvc.Components.get(ID).getVisualization(function (tableView) {
                                // Register custom cell renderer, the table will re-render automatically
                                totalResults = 1;
                                tableView.addCellRenderer(new RangeMapIconRenderer());
                        });
                })
        });       
    });     
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Will really appreciate any help regarding this issue. &lt;/P&gt;

&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2018 10:33:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-Javascript-not-running-until-I-click-on-quot-Edit-quot/m-p/437479#M41228</guid>
      <dc:creator>pinggg</dc:creator>
      <dc:date>2018-07-13T10:33:16Z</dc:date>
    </item>
    <item>
      <title>Re: Why is Javascript not running until I click on "Edit" , and it runs twice after that?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-Javascript-not-running-until-I-click-on-quot-Edit-quot/m-p/437480#M41229</link>
      <description>&lt;P&gt;Have tried by requiring &lt;CODE&gt;'splunkjs/ready!'&lt;/CODE&gt;  with other js ?&lt;BR /&gt;
Like &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; require([
     'underscore',
     'jquery',
     'splunkjs/mvc',
     'splunkjs/mvc/tableview',
     'splunkjs/ready!',
     'splunkjs/mvc/simplexml/ready!'
 ], function (_, $, mvc, TableView) { 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;instead of&lt;/STRONG&gt; &lt;/P&gt;

&lt;P&gt;require(['splunkjs/ready!'], function () {&lt;BR /&gt;
     require([&lt;BR /&gt;
         'underscore',&lt;BR /&gt;
         'jquery',&lt;BR /&gt;
         'splunkjs/mvc',&lt;BR /&gt;
         'splunkjs/mvc/tableview',&lt;BR /&gt;
         'splunkjs/mvc/simplexml/ready!'&lt;BR /&gt;
     ], function (_, $, mvc, TableView) { &lt;/P&gt;</description>
      <pubDate>Fri, 13 Jul 2018 15:33:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-Javascript-not-running-until-I-click-on-quot-Edit-quot/m-p/437480#M41229</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2018-07-13T15:33:31Z</dc:date>
    </item>
    <item>
      <title>Re: Why is Javascript not running until I click on "Edit" , and it runs twice after that?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-Javascript-not-running-until-I-click-on-quot-Edit-quot/m-p/437481#M41230</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Thanks for your reply. I have tried it, however it does not work as it results in nothing printed at all &lt;STRONG&gt;even&lt;/STRONG&gt; after "Edit" and "Cancel" button is clicked. &lt;/P&gt;</description>
      <pubDate>Mon, 16 Jul 2018 02:30:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-Javascript-not-running-until-I-click-on-quot-Edit-quot/m-p/437481#M41230</guid>
      <dc:creator>pinggg</dc:creator>
      <dc:date>2018-07-16T02:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: Why is Javascript not running until I click on "Edit" , and it runs twice after that?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-Javascript-not-running-until-I-click-on-quot-Edit-quot/m-p/672823#M55108</link>
      <description>&lt;P&gt;Hi Pinggg&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm facing the same issue and do not understand where the issue is.. Did you by any chance find a solution?&lt;/P&gt;&lt;P&gt;Thanks 1000!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Greetings&lt;/P&gt;</description>
      <pubDate>Thu, 28 Dec 2023 09:11:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Why-is-Javascript-not-running-until-I-click-on-quot-Edit-quot/m-p/672823#M55108</guid>
      <dc:creator>rjoller</dc:creator>
      <dc:date>2023-12-28T09:11:37Z</dc:date>
    </item>
  </channel>
</rss>

