Splunk Search

Table drilldown: Disable link conditionally

enexwhy
Explorer

I have a table with cell drilldown enabled.
However, in certain conditions I want to disable the drilldown, for example:
alt text

I want the drilldown to be enabled for 'pass' but not for 'fail'.
I have some code in my .js file but it does not work. I am not very familiar with JavaScript.

Anyway this is what I want to achieve:
// Disables cells conditionally
var table1 = mvc.Components.get('table1');

table1.on('click', function(cell) {
    console.log(cell.field);
    console.log(cell.value); // I can get cell.field, but not cell.value -- how can I get cell.value?

    if (cell.field == 'status' && cell.value == 'fail') {
        cell.preventDefault(); // Disable the drilldown here
    }
});
0 Karma
1 Solution

jeffland
SplunkTrust
SplunkTrust

You could use the cell.data object to get the required info. It contains everything also available for the Simple XML drilldown actions, such as click.name2 and so on. You'll want these two:

cell.data["click.name2"] // name of the clicked cell
cell.data["click.value2"] // value of the clicked cell

By the way, if you want to learn and understand what's happening, I recommend using your browsers developer tools, namely the debugger, to set breakpoints and check which objects are available and which info they contain. For example, you could set a breakpoint on the first line of the anonymous function you call on('click' and check out the cell object. In Chrome and Firefox, you press F12 and go to the Debugger tab. In the list of sources, look for your js file.
If you're on 6.5 and above, you'll need to insert a debugger; statement in your js file to make it appear in the list of sources, see here (answer by rjthibod) for source.

View solution in original post

jeffland
SplunkTrust
SplunkTrust

You could use the cell.data object to get the required info. It contains everything also available for the Simple XML drilldown actions, such as click.name2 and so on. You'll want these two:

cell.data["click.name2"] // name of the clicked cell
cell.data["click.value2"] // value of the clicked cell

By the way, if you want to learn and understand what's happening, I recommend using your browsers developer tools, namely the debugger, to set breakpoints and check which objects are available and which info they contain. For example, you could set a breakpoint on the first line of the anonymous function you call on('click' and check out the cell object. In Chrome and Firefox, you press F12 and go to the Debugger tab. In the list of sources, look for your js file.
If you're on 6.5 and above, you'll need to insert a debugger; statement in your js file to make it appear in the list of sources, see here (answer by rjthibod) for source.

enexwhy
Explorer

Hi jeffland, thank you for your response.

I changed 'cell.field' and 'cell.value' to those you mentioned, but I do not see .preventDefault() working.
Even if I try the simplest thing that I can:
var table1 = mvc.Components.get('table1');

table1.on('click', function(cell) {
    cell.preventDefault(); // When I place a breakpoint here and click on table1, the drilldown takes place even before this line executes.
    var col = cell.data['click.name2'];
    var val = cell.data['click.value2'];
});
0 Karma

jeffland
SplunkTrust
SplunkTrust

That has to be caused by something else you do on your dashboard. You could start from a minimal example like this Simple XML:

<dashboard script="preventDrilldown.js">
  <label>Preventing Drilldown</label>
  <row>
    <panel>
      <table id="table">
        <search>
          <query>index=_internal | stats count by group</query>
          <earliest>-15m</earliest>
          <latest>now</latest>
        </search>
      </table>
    </panel>
  </row>
</dashboard>

and this javascript:

require([
    "splunkjs/mvc",
    "splunkjs/mvc/simplexml/ready!"
], function (mvc) {
    var table = mvc.Components.get("table");
    table.on("click", function (cell) {
        cell.preventDefault();
    });
});

This has to work. From there, add features you have on your original dashboard until you hit the culprit. Unfortunately, that's all I can do from here 😞

0 Karma

enexwhy
Explorer

I figured it out. I had to remove all the drilldowns I defined in the XML, and redefine them in the .js file. I was thinking that .preventDefault() would stop those from happening but then I realized that 'default' means the default drilldown that produces the search query based on the cell you click on.

Thanks again for your responses.

0 Karma
Get Updates on the Splunk Community!

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...