Splunk Dev

Changing multiple tables in SimpleXML using SplunkJS

pgullette
Explorer

I need to be able to modify the behavior of any number of tables on a dashboard created with SimpleXML. I have my custom JavaScript added to the page and running properly. I am using mvc.Components.getInstances() to get a full list of all components on the page, and this is working as expected. Also, I'm using splunkjs/mvc/simplexml/ready! as a dependency so that my JavaScript executes after everything is ready. And I should mention that I'm using getInstances() instead of getInstance() because I want the behavior to be generic for any number of tables.

Here's where the problem is. When I iterate through my instances returned by getInstances(), certain properties are not yet available. Specifically, since I am trying to manipulate tables on the dashboard, I am unable to access the visualization member as it's NULL at the time my code is running. What is the proper way to manipulate a SimpleXML table after it's fully loaded? And another related question, is there an easy way to determine if an object returned by getInstances() is specifically a table without looking for a specific property?

Thanks for any help.

0 Karma

helenashton
Path Finder

Did you find a solution? I would also like to address all Tables (unknown ids).

0 Karma

spongmob
Explorer

So we started off running a loop finding ".table.splunk-view".each". We were then able to get the attribute "id" of each instance. From there we went about it in a similar manner as Marco's solution below by plugging in the id we gathered in the previous step.

Hope this helps!

0 Karma

helenashton
Path Finder

It does (that's exactly what I am trying to do), but it would be great if you could share that snippet of code 🙂

0 Karma

marco_sulla
Path Finder
var libs = [
    "jquery",
    "splunkjs/mvc",
    "splunkjs/mvc/simplexml/element/table",
    "splunkjs/mvc/simplexml/ready!",
];

require(libs, function ($, mvc, TableElement) {
    "use strict";

    $.each(mvc.Components.getInstances(), function (i, view) {
        /**
         *  @author Marco Sulla (marcosullaroma@gmail.com)
         *  @date Jan 31, 2015
         */

        if (view instanceof TableElement) {
            view.getVisualization(function (view) {
                view.on("rendered", function () {
                    console.log(view);
                 });
            });
        }
    });
});

Sources:
Web Framework Reference
Examples App
share/splunk/search_mrsparkle/exposed/js/build/simplexml/mvc.js source code

spongmob
Explorer

Curious to see if you figured out a solution to this problem.

Thanks,

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...

Introduction to Splunk AI

How are you using AI in Splunk? Whether you see AI as a threat or opportunity, AI is here to stay. Lucky for ...