I have the following code that I am using from this link (modified slightly) to remove or add my All select as needed. Works perfectly for my input 2....but I have 5 more inputs I want it to do the exact same functionality on. I can't really find much documentation on the methods available for mvc.Components, so I can't tell if there is a getClass, or some similar functionality. Anyone have a clue on how I can do below, but for all inputs matching input2 - input8? Relevant code is from line 11 through 34
Edit: Can't add links to answers from this site yet.....
require(['jquery','underscore','splunkjs/mvc', 'website_status_cell_renderer', 'splunkjs/mvc/simplexml/ready!'],
function($, _, mvc, WebsiteStatusCellRenderer){
var statusTable = mvc.Components.get('element2');
statusTable.getVisualization(function(tableView){
tableView.table.addCellRenderer(new WebsiteStatusCellRenderer());
tableView.table.render();
});
var selection = [];
var multi = mvc.Components.getInstance("input2");
multi.on("change", function(){
// get the current selection
selection = multi.val();
// check if there is more than one entry and one of them is "*"
if (selection.length > 1 && ~(selection.indexOf("*"))) {
if (selection.indexOf("*") == 0) {
// "*" was first, remove it and leave rest
selection.splice(selection.indexOf("*"), 1);
multi.val(selection);
multi.render();
} else {
// "*" was added later, remove rest and leave "*"
multi.val("*");
multi.render();
}
} else if ( selection.length < 1){
multi.val("*");
multi.render();
}
});
}
);
If you know that inputs 2 through 8 need to be modified, you could just use a function to iterate through the inputs accordingly:
function setupMultiInput(instance_id){
var multi = mvc.Components.getInstance(instance_id);
multi.on("change", function(){
// get the current selection
selection = multi.val();
// check if there is more than one entry and one of them is "*"
if (selection.length > 1 && ~(selection.indexOf("*"))) {
if (selection.indexOf("*") == 0) {
// "*" was first, remove it and leave rest
selection.splice(selection.indexOf("*"), 1);
multi.val(selection);
multi.render();
} else {
// "*" was added later, remove rest and leave "*"
multi.val("*");
multi.render();
}
} else if ( selection.length < 1){
multi.val("*");
multi.render();
}
});
}
for(var c = 2; c <= 8; c++){
setupMultiInput("input" + c);
}
If you know that inputs 2 through 8 need to be modified, you could just use a function to iterate through the inputs accordingly:
function setupMultiInput(instance_id){
var multi = mvc.Components.getInstance(instance_id);
multi.on("change", function(){
// get the current selection
selection = multi.val();
// check if there is more than one entry and one of them is "*"
if (selection.length > 1 && ~(selection.indexOf("*"))) {
if (selection.indexOf("*") == 0) {
// "*" was first, remove it and leave rest
selection.splice(selection.indexOf("*"), 1);
multi.val(selection);
multi.render();
} else {
// "*" was added later, remove rest and leave "*"
multi.val("*");
multi.render();
}
} else if ( selection.length < 1){
multi.val("*");
multi.render();
}
});
}
for(var c = 2; c <= 8; c++){
setupMultiInput("input" + c);
}
Thanks. Exactly what I needed. Not sure why I didn't think of it yesterday, brain must have been fried from learning how to do dashboards.
haha, we have all been there :).
BTW: I noticed you are using the WebsiteStatusCellRenderer. May I presume thats one from the Website Monitoring app? I'm just curious if you were making changes to that app or if you were using for something new. Let me know if you need any help with that too.