How can I add functionality to a button to make it append results to a csv file?
Currently I have the following js (@kamlesh_vaghela s - given in this answer)
require([
'underscore',
'jquery',
'splunkjs/mvc',
'splunkjs/mvc/tableview',
'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView) {
// Access the "default" token model
var tokens = mvc.Components.get("default");
var selected_values_array = [];
var submittedTokens = mvc.Components.get('submitted');
var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
canRender: function(cell) {
return _(['checkbox']).contains(cell.field);
},
render: function($td, cell) {
var a = $('<div>').attr({"id":"chk-sourcetype"+cell.value,"value":cell.value})
.addClass('checkbox').click(function() {
// console.log("checked",$(this).attr('class'));
// console.log("checked",$(this).attr('value'));
if($(this).attr('class')==="checkbox")
{
selected_values_array.push($(this).attr('value'));
$(this).removeClass();
$(this).addClass("checkbox checked");
}
else {
$(this).removeClass();
$(this).addClass("checkbox");
var i = selected_values_array.indexOf($(this).attr('value'));
if(i != -1) {
selected_values_array.splice(i, 1);
}
// Change the value of a token $mytoken$
}
console.log(selected_values_array);
}).appendTo($td);
}
});
//List of table IDs
var tableIDs = ["myTable"];
for (i=0;i<tableIDs.length;i++) {
var sh = mvc.Components.get(tableIDs[i]);
if(typeof(sh)!="undefined") {
sh.getVisualization(function(tableView) {
// Add custom cell renderer and force re-render
tableView.table.addCellRenderer(new CustomRangeRenderer());
tableView.table.render();
});
}
}
$(document).ready(function () {
$("#mybutton").on("click", function (e) {
e.preventDefault();
console.log("in");
tokens.set("mytoken", selected_values_array.join());
submittedTokens.set(tokens.toJSON());
});
});
});
Is there a way to make the button only perform an outputlookup to append the chosen values to a CSV file?
I have the following dashboard, which does add the rows succesfully to a csv, but it also shows a search panel with the results. I don't need this, but I dont know how to make the button only update the csv?
<form script="checkboxes.js" stylesheet="my.css">
<row>
<panel>
<table id="myTable">
<title>My Table</title>
<search>
<query>index=_internal NOT [|inputlookup dontshow | fields sourcetype] | stats count by sourcetype | eval checkbox=sourcetype</query>
<earliest>-15m</earliest>
<latest>now</latest>
</search>
<option name="count">10</option>
<option name="drilldown">row</option>
<drilldown>
<condition field="*">
</condition>
</drilldown>
</table>
</panel>
</row>
<row>
<html>
<div>
<input type="button" id="mybutton" value="My Button" />
</div>
</html>
</row>
<row>
<panel>
<table>
<title>My Selected Value</title>
<search>
<query>| makeresults | eval sourcetype="$mytoken$" | makemv delim="," sourcetype | stats count by sourcetype | table sourcetype | outputlookup append=t dontshow.csv </query>
<earliest>-15m</earliest>
<latest>now</latest>
</search>
<option name="count">10</option>
<option name="drilldown">none</option>
</table>
</panel>
</row>
</form>
... View more