<?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 SplunkJS search results not loading table every time in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/SplunkJS-search-results-not-loading-table-every-time/m-p/513896#M34303</link>
    <description>&lt;P&gt;The following is my JS code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&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/searchmanager",
    "splunkjs/mvc/tableview",
    "splunkjs/mvc/simplexml/ready!"
], function(_, $, mvc, SearchManager, TableView) {

    var mySearch = splunkjs.mvc.Components.getInstance("main_search");

    var myResults = mySearch.data("results");
    myResults.on("data", function(){
        allFields = myResults.data().fields;
        filteredFields = allFields.filter(field =&amp;gt; !consistentFields.includes(field));        
    });
    var filteredFields;

    var consistentFields = ["Field 1", "Field 2", "Field 3" ];


    var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
        canRender: function(cell) {
            return true;
        },
        render: function($td, cell) {
            
            if(filteredFields.includes(cell.field)){
                if (cell.value === "Failure") {
                    $td.addClass("failure");
                }
                else if (cell.value === "Warn") {
                    $td.addClass("warn");
                }
                else if (cell.value === "Success") {
                    $td.addClass("success");
                }
            }
            // Update the cell content
            $td.text(cell.value).addClass("string");
        }
    });
    mvc.Components.get("main_table").getVisualization(function(tableView) {
        // Add custom cell renderer, the table will re-render automatically.
        tableView.addCellRenderer(new CustomRangeRenderer());
    }); 
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not having the table load every time as I look at my console and I am getting the following error message&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;U&gt;&lt;EM&gt;&lt;SPAN class="message-body-wrapper"&gt;&lt;SPAN class="message-flex-body"&gt;&lt;SPAN class="message-body devtools-monospace"&gt;Uncaught &lt;SPAN class="objectBox-stackTrace reps-custom-format"&gt;TypeError: &lt;SPAN class="objectBox objectBox-string"&gt;myResults.data() is undefined&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/EM&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="message-body-wrapper"&gt;&lt;SPAN class="message-flex-body"&gt;&lt;SPAN class="message-body devtools-monospace"&gt;&lt;SPAN class="objectBox-stackTrace reps-custom-format"&gt;&lt;SPAN class="objectBox objectBox-string"&gt;This issue is my hunch for why my code works but not every single time since the page won't necessarily load.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 13 Aug 2020 12:28:40 GMT</pubDate>
    <dc:creator>yash07</dc:creator>
    <dc:date>2020-08-13T12:28:40Z</dc:date>
    <item>
      <title>SplunkJS search results not loading table every time</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/SplunkJS-search-results-not-loading-table-every-time/m-p/513896#M34303</link>
      <description>&lt;P&gt;The following is my JS code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&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/searchmanager",
    "splunkjs/mvc/tableview",
    "splunkjs/mvc/simplexml/ready!"
], function(_, $, mvc, SearchManager, TableView) {

    var mySearch = splunkjs.mvc.Components.getInstance("main_search");

    var myResults = mySearch.data("results");
    myResults.on("data", function(){
        allFields = myResults.data().fields;
        filteredFields = allFields.filter(field =&amp;gt; !consistentFields.includes(field));        
    });
    var filteredFields;

    var consistentFields = ["Field 1", "Field 2", "Field 3" ];


    var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
        canRender: function(cell) {
            return true;
        },
        render: function($td, cell) {
            
            if(filteredFields.includes(cell.field)){
                if (cell.value === "Failure") {
                    $td.addClass("failure");
                }
                else if (cell.value === "Warn") {
                    $td.addClass("warn");
                }
                else if (cell.value === "Success") {
                    $td.addClass("success");
                }
            }
            // Update the cell content
            $td.text(cell.value).addClass("string");
        }
    });
    mvc.Components.get("main_table").getVisualization(function(tableView) {
        // Add custom cell renderer, the table will re-render automatically.
        tableView.addCellRenderer(new CustomRangeRenderer());
    }); 
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not having the table load every time as I look at my console and I am getting the following error message&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;&lt;U&gt;&lt;EM&gt;&lt;SPAN class="message-body-wrapper"&gt;&lt;SPAN class="message-flex-body"&gt;&lt;SPAN class="message-body devtools-monospace"&gt;Uncaught &lt;SPAN class="objectBox-stackTrace reps-custom-format"&gt;TypeError: &lt;SPAN class="objectBox objectBox-string"&gt;myResults.data() is undefined&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/EM&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="message-body-wrapper"&gt;&lt;SPAN class="message-flex-body"&gt;&lt;SPAN class="message-body devtools-monospace"&gt;&lt;SPAN class="objectBox-stackTrace reps-custom-format"&gt;&lt;SPAN class="objectBox objectBox-string"&gt;This issue is my hunch for why my code works but not every single time since the page won't necessarily load.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2020 12:28:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/SplunkJS-search-results-not-loading-table-every-time/m-p/513896#M34303</guid>
      <dc:creator>yash07</dc:creator>
      <dc:date>2020-08-13T12:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: SplunkJS search results not loading table every time</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/SplunkJS-search-results-not-loading-table-every-time/m-p/514241#M34341</link>
      <description>&lt;P&gt;Can you add further details for code with table with id &lt;STRONG&gt;main_table&lt;/STRONG&gt; and search with id &lt;STRONG&gt;main_search&lt;/STRONG&gt;? Is the search linked with the table i.e. present within table? Try to put the following at the beginning of your code and step through each JS debug step in Browser or Debugger of your preference to see which step is actually failing.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;console.log("Script Loaded");&lt;/LI-CODE&gt;&lt;P&gt;Most important part is whether it is entering table render code and classes are being added or not.&lt;BR /&gt;&lt;BR /&gt;If you are using code from the following post you may also have to ensure that null fields are handled in SPL using fillnull.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-get-the-Table-cell-colorization-rendering-for-every/td-p/289392" target="_blank"&gt;https://community.splunk.com/t5/Dashboards-Visualizations/How-can-I-get-the-Table-cell-colorization-rendering-for-every/td-p/289392&lt;/A&gt;&lt;BR /&gt;or&amp;nbsp;&lt;BR /&gt;&lt;A href="https://community.splunk.com/t5/Splunk-Search/Add-colors-to-a-table-for-dynamic-columns/td-p/411419" target="_blank"&gt;https://community.splunk.com/t5/Splunk-Search/Add-colors-to-a-table-for-dynamic-columns/td-p/411419&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Aug 2020 15:30:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/SplunkJS-search-results-not-loading-table-every-time/m-p/514241#M34341</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-08-15T15:30:20Z</dc:date>
    </item>
  </channel>
</rss>

