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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...