Dashboards & Visualizations

Token value change does not update Search Manager

johannschmid
New Member

Hi,

Generally I want to have an text input field where you can enter an String which updates the table view.
Now when I am opening the Site he uses the default value of the text input field, but when I am changing the text in the txt input field the table view will not get updated. Do you have any hints what the problem is?

Regards Johann

JavaScript:

require([
    'jquery',
    'underscore',
    'splunkjs/ready!',
    'splunkjs/mvc/searchmanager',
    'splunkjs/mvc/tableview',
    'splunkjs/mvc/textinputview',
    ],
    function(
       $,
        _,
        mvc,
        SearchManager,
        TableView,
        TextInputView
    ) {

        var tokens = mvc.Components.getInstance("default");

        var tableView1 = new TableView({
            id: 'table1',
            managerid: 'simplesearch1',
            el: $('#table1')
        }).render();

        var table2 = new TableView({
            id: 'table2',
            managerid: 'simplesearch1',
            el: $('#table2')
        }).render();

           var textinput1 = new TextInputView({
                 id: "tf",
                default: "*",
                  value: mvc.tokenSafe("$searchQuery$"),
                  el: $("#tf")
            }).render();

        var ICONS = {
            severe: 'alert-circle',
            elevated: 'alert',
            low: 'check-circle'
        };

        var CustomIconCellRenderer = TableView.BaseCellRenderer.extend({
            canRender: function(cell) {
                return cell.field === 'range';
            },

            render: function($td, cell) {
                var icon = 'question';
                if(ICONS.hasOwnProperty(cell.value)) {
                    icon = ICONS[cell.value];
                }
                $td.addClass('icon').html(_.template('<i class="icon-<%-icon%> <%- range %>" title="<%- range %>"></i>', {
                    icon: icon,
                    range: cell.value
                }));
            }
        });



        new SearchManager({
            id: 'simplesearch1',
            search: mvc.tokenSafe("index=_internal | search $searchQuery$ | head 10000 | stats count by sourcetype,source,host | rangemap field=count low=0-100 elevated=101-1000 default=severe"),
            //cache: true,
            preview: true,
            //autostart: true
        });

        tableView1.table.addCellRenderer(new CustomIconCellRenderer());
        tableView1.table.render();
    }
);

XML:

<dashboard script="ip_profiler.js" stylesheet="ip_profiler.css">

  <row>
    <panel>
        <html>
          <div id="tf"></div>
      </html>
    </panel>
  </row>

  <row>
 <panel>
      <table id="table1">
        <option name="wrap">undefined</option>
        <option name="rowNumbers">undefined</option>
        <option name="drilldown">row</option>
      </table>
    </panel>
  </row>
</dashboard>
0 Karma

s2_splunk
Splunk Employee
Splunk Employee

It looks like you are missing the code to react to the text input value change, like so:
textinput1.on("change", function(newValue) {
FormUtils.handleValueChange(textinput1);
});

I would try adding that and see if it executes your search again.

0 Karma
Get Updates on the Splunk Community!

New This Month - Splunk Observability updates and improvements for faster ...

What’s New? This month, we’re delivering several enhancements across Splunk Observability Cloud for faster and ...

What's New in Splunk Cloud Platform 9.3.2411?

Hey Splunky People! We are excited to share the latest updates in Splunk Cloud Platform 9.3.2411. This release ...

Buttercup Games: Further Dashboarding Techniques (Part 6)

This series of blogs assumes you have already completed the Splunk Enterprise Search Tutorial as it uses the ...