Dashboards & Visualizations
Highlighted

Learning to include jquery in simple xml

Path Finder

Hi to all, i'm just learning to usi a little of custom jquery in splunk simple dashboard.
I have this at begining of my xml:

<form script="script.js" stylesheet="dark.css">

in script.js i have this:

require([
     'jquery',
     'splunkjs/mvc/simplexml/ready!'
 ], function($) {
    $(document).ready(function() {
        $( "#row1" ).addClass( "red" );
    }); 
});

just a stupid code to see if it's works, but it does not.

Of cource in .css i have the class red. Even if i run in the chrome console:$( "#row1" ).addClass( "red" ); nothing happens.

Could you please help me?

Thanks and regards.

Tags (3)
0 Karma
Highlighted

Re: Learning to include jquery in simple xml

Communicator

Your sample code does work, so my guess is that your script isn't being seen by Splunk and isn't loading. View the page source to see if Splunk was able to find it and load it into your dashboard.

The CSS should appear in the head tag:

<head>
    ...
    <link rel="stylesheet" type="text/css" media="all" href="/en-US/static/@264376:0/app/search/dark.css" />
    ...
</head>

The JavaScript should be at the bottom of the page just before the closing of the body tag:

    <script src="/en-US/static/@264376:0/app/search/script.js" type="text/javascript"></script>
</body>

Usually in order to get my new scripts and css files to populate in a dashboard I need to restart Splunk.

Highlighted

Re: Learning to include jquery in simple xml

Path Finder

As @justinatpnnl pointed out, your Javascript is probably not included in the web page because the Splunk server has not yet noticed your new Javascript file.

To make a new Javascript file available without a full server restart:

$SPLUNK_HOME/bin/splunk restartss

To force a reload of a changed Javascript file:

http(s)://localhost:8000/en-US/_bump

and click the button there to increment the version number.

Highlighted

Re: Learning to include jquery in simple xml

Path Finder

Thanks to all. It works, but it seems that i need a splunkweb restart every time i modify a css or js, is it normal?
Thanks and regards

0 Karma
Highlighted

Re: Learning to include jquery in simple xml

Communicator

No, a restart isn't necessary every time. If you use the link @kurdbahr provided in the second part of his answer, it creates a new cache for JavaScript and CSS files and then you can just refresh the page.

http://your_splunk_server/en-US/_bump
Highlighted

Re: Learning to include jquery in simple xml

Path Finder
0 Karma
Highlighted

Re: Learning to include jquery in simple xml

Legend

@renjujacob88 it is actually http://<splunkURLPort>/en-US/debug/refresh. For Development or Non-prod instances, _bump, debug refresh or Development mode settings are recommended.

Following is the URL to turn on Development Mode settings with no caching: https://docs.splunk.com/Documentation/Splunk/latest/AdvancedDev/CustomVizTutorial#Development_mode_s...




| eval message="Happy Splunking!!!"


0 Karma