cancel
Showing results for 
Search instead for 
Did you mean: 

How to hide a column in a table widget?

DXC
7 - Data Storage
7 - Data Storage

Does anyone know how to hide a column in a table widget?

I saw the old post here (https://community.sisense.com/t5/build-analytics/pivot-2-0-hiding-columns-from-the-display/td-p/3607) for pivot table but that doesn't work on table widget. 

Thank you. 

7 REPLIES 7

Sijo1995
9 - Travel Pro
9 - Travel Pro

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
7 - Data Storage
7 - Data Storage

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

Benji_PaldiTeam
11 - Data Pipeline
11 - Data Pipeline

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 

 

Jordan_gues
7 - Data Storage
7 - Data Storage

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'
        }
      }
    })
  }
);

harikm007
13 - Data Warehouse
13 - Data Warehouse

Hi @DXC ,

Try below script to hide a column from Table widget (not Pivot)

https://www.binextlevel.com/post/hide-a-column-from-table-widget

harikm007_0-1677579660883.png

-Hari

 

hvibberts
8 - Cloud Apps
8 - Cloud Apps

this is exactly what i need but I need to hide multiple columns.   How do we do that?

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});
});