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!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...