Forum Discussion

7 Replies

Replies have been turned off for this discussion
  • this is exactly what i need but I need to hide multiple columns.   How do we do that?

    • rvickersevotix's avatar
      rvickersevotix
      Cloud Apps
      widget.on('domready', function(se, ev){
      
        // Specify the column indices to hide
        let columnIndices = [1, 3, 5];
      
        // Function to hide columns
        function hideColumns() {
          columnIndices.forEach(function(columnIndex) {
            $(`table tr > *:nth-child(${columnIndex})`, element).css('display', 'none');
          });
        }
      
        // Initial hiding of columns
        hideColumns();
      
        // Observe changes in the table body
        const elementToObserve = $('table tbody', element)[0];
        const observer = new MutationObserver(function(e) {
          for(const m of e) {
            if (m.type === 'childList') {
              $.each(m.addedNodes, function(index, value){
                // Hide columns in added rows
                columnIndices.forEach(function(columnIndex) {
                  $(value).find(`td:nth-child(${columnIndex})`).css('display', 'none');
                });
              });
            }
          }
        });
      
        observer.observe(elementToObserve, {subtree: true, childList: true});
      });
  • Hi DXC try this 

    columnsToHide = [1]
    
    widget.transformPivot(
      {},
      function (metadata, cell) 
      {
        columnsToHide.forEach(function(col) {
          if (metadata.colIndex == col) { // Add a second condition ( && metadata.rowIndex > 0 ) if you want to keep the table header
            cell.content = ' '
            cell.style = { 
              maxWidth: '0px', 
              borderColor: 'white',
              color: 'white'
            }
          }
        })
      }
    );
  • Hi DXC ,

    As I'm pretty sure it can be handled by script you might be interested in a stable code-free solution which is the "Control Table Columns" by Paldi solutions.

    With this plugin, viewers can decide which columns they want to see and which they want to hide in table widget.

    Let me know if you would like to trial this plugin and feel free to reach out of you have further questions, we're always happy to help (: 

     

    Paldi Solutions - Number #1 Sisense Plugins Developer 

     

  • Hi DXC ,

    Please try this script 

    This is for Linux script

     

    var newWidth = {
    0: 0,         //hide column index
    1: 100,
    2: 100
    
    
    }
    var columnsToRemove = []
    var passed = -1
    var wasExecuted = false
    widget.on('processresult', function(widget, args){
    if (!wasExecuted) {
    args.result.metadata.forEach(function(e, index) {
    e.panel
    if (e.panel != "scope" ) {
    index = Object.keys(newWidth).length - index+passed;
    if ( typeof(newWidth[index]) !== "undefined" ) {
    e["format"] = {"width":newWidth[index]};
    }
    if (e.format.width === 0) {
    columnsToRemove.push(index)
    }
    }
    else {
    passed ++
    }
    })
    wasExecuted = true
    }
    })
    widget.on('ready', function() {
    columnsToRemove.forEach(function(item) {
    var selector = "[class*=table-grid__cell--col-" + item +"]";
    $(selector, element).each(function(i, lmnt) {
    $(lmnt).text('')
    })
    })
    })
    
    

     

     

    Thanks

    Sijo

    • DXC's avatar
      DXC
      Cloud Apps

      Thank you for sharing, but this one is not working on table still...