Jump to content

How to use a variable in javascript to delete columns for tabular datapages


Recommended Posts

This is part of a solution I'm working on to let the user select which columns to hide in a tabular report. In this post I need to figure out how to use a Virtual field's value, as a variable, in the actual 'delete code.' Once I get the whole think worked out I'll post a unified thread with the whole process, as I think it would be helpful for a lot of users. 

The code below is what I'm working with. This is all in the Search form of a tabular datapage and the js is in the footer.

The user multi-selects from a Virtual ListBox (Virtual2) and I need the code below to get that value, use it as a variable and then put that string in the "deleting();" line at the bottom. Normally that line looks something like "deleting(8,7,6,3,2);" but instead of having integers written there I need it to use a variable "v_coldelete" so it can be from user input. 

Something's wrong with how I'm trying to use the variable but I can't figure out what. 

///REMOVE COLUMNS

document.addEventListener('DataPageReady', function (event) {
   
   var v_coldelete = document.getElementById("cbParamVirtual2").value;
  
    const check = document.querySelectorAll('table[data-cb-name="cbTable"] th');
    if(check.length===17){
        const deleting = (...args) =>{
               let label, values
               for(let a of args){
                      label = document.querySelector(`table[data-cb-name="cbTable"] th:nth-of-type(${a})`);
                      values = document.querySelectorAll(`table[data-cb-name="cbTable"] td:nth-of-type(${a})`);
                      label.parentElement.removeChild(label);

                      values.forEach(el => {
                            el.parentElement.removeChild(el);
                      });
               }
        }
        
        /* In below function call, just put any number of column you want to hide, but in reverse order - from highest number to the lowest */
        /**normally in the line below would look something like deleting (9,8,7,3,2) and would delete those columns. I'm using Virtual2 to get the comma delimited string the user selects in a Virtual List box. I need to put it like in below but it's not working  */
     
        deleting(v_coldelete);
    }
});

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...