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!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...