Splunk Search

How to use Javascript in creating tables?

josefa123
Explorer

Here is my XML in Splunk Web

<dashboard script="yeahboy.js">
  <label>Sample Dashboard</label>
</dashboard>

And this is my Javascript code

/**
 * Created by micoh on 7/29/2015.
 */
require(["splunkjs/ready!"], function(mvc) {
    var deps = [
        "jquery",
        "splunkjs/ready!",
        "splunkjs/mvc/searchmanager",
        "splunkjs/mvc/tableview"
    ];
    require(deps, function(mvc) {
        var SearchManager = require("splunkjs/mvc/searchmanager");
        new SearchManager({
            id: "search1",
            earliest_time: "rt-1w",
            latest_time: "rtnow",
            search: "* | bucket _time span=1m | stats values(memUsedPct) by host _time",
            preview: true,
            autostart: true,
            cache: true

        });
        var TableView = require('splunkjs/mvc/tableview');
        var element1 = new TableView({
            id: "element1",
            count: 10,
            dataOverlayMode: "none",
            drilldown: "cell",
            rowNumbers: "false",
            wrap: "true",
            managerid: "search1",
            el: $("#myTable")
        });
    });
});

Here is my dashboard

alt text

I am new on using SplunkJS. I've researched on how to use it to create tables and I think I have a correct code.

0 Karma
1 Solution

jeffland
SplunkTrust
SplunkTrust

Everything is looking good so far, but you are missing the link that tells splunk where to put your table. In javascript, you instructed the TableView to use the element #mytable for its position, but there is no such thing in you Simple XML. Adding these three lines below your label tag should do it:

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

View solution in original post

jeffland
SplunkTrust
SplunkTrust

Everything is looking good so far, but you are missing the link that tells splunk where to put your table. In javascript, you instructed the TableView to use the element #mytable for its position, but there is no such thing in you Simple XML. Adding these three lines below your label tag should do it:

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

josefa123
Explorer

Thanks. It works!

0 Karma
Get Updates on the Splunk Community!

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Index This | What goes away as soon as you talk about it?

May 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...

What's New in Splunk Observability Cloud and Splunk AppDynamics - May 2025

This month, we’re delivering several new innovations in Splunk Observability Cloud and Splunk AppDynamics ...