Splunk Dev

Checkbox not getting enabled on change in token value

its_shubham
Engager

I have javascript code of which job is to check checkboxes on change in token value:

This is for rendering of the checkbox:

 

var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
         canRender: function(cell) {
             return _(['Check for Prediction']).contains(cell.field);
         },
         render: function($td, cell) {
             
             var a = $('<div>').attr({"id":"chk-sourcetype"+cell.value,"value":cell.value}).addClass('checkbox').click(function() {
                 
                 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(val_arr[1]);
                 console.log(selected_values_array);
             }).appendTo($td);

                
             
         }
     });​

 



This is my on change condition:

 

tokens.on("change:mytoken2", function() {
        tokenVal=tokens.get("mytoken2");
        console.log("mytoken2onchange: " + tokenVal);
        if (tokenVal=='value changed') {

            console.log('inside on:change...')
        var tableIDs = ["myTable"];
        
        for (i=0;i<tableIDs.length;i++) {
            var sh = mvc.Components.get(tableIDs[i]);
            // console.log(sh)
            if(typeof(sh)!="undefined") {
                sh.getVisualization(function(tableView) {
                    // Add custom cell renderer and force re-render
                    tableView.table.addCellRenderer(new CustomRangeRenderer());
                    tableView.table.render();
                });
            }
        }
     }
​

 


This is default:
Screenshot 1

Screenshot 1.png

And on click of a button, there will be change in token value and as a result of which the column 'Selected' whereever value is 'Yes', the checkbox corresponding to that row must get enabled:
Screenshot 2

 

Screenshot 2.png

Please feel free to shoot your questions if anything is not clear.

 

 

 

Labels (4)
0 Karma

thambisetty
SplunkTrust
SplunkTrust

share simple xml.

————————————
If this helps, give a like below.
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...