Forum Discussion

Ophir_Buchman's avatar
Ophir_Buchman
Data Integration
06-16-2022

Pivot 2.0 - Hiding Columns from the Display

When creating a Pivot 2.0 chart (Linux) you may want to hide a specific column.
There are various reasons for doing so:
  • I want to sort by a column that shouldn't be displayed
  • I want to display a column when exporting the table to Excel or CSV, but hide it on the dashboard

Add the following widget script to your pivot chart:

columnsToHide = [3,4]

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

1 Reply

Replies have been turned off for this discussion
  • Anonymous's avatar
    Anonymous

    Note: If you have multiple pivot tables in your dashboard, put this inside the initialized event of the widget and declare columnsToHide as a const variable

    widget.on('initialized', function (ev, se) {
    	const columnsToHide = [3,4]
    
    	widget.transformPivot(
    	  {},
    	  function (metadata, cell) 
    	  {
    		columnsToHide.forEach(function(col) {
    		  if (metadata.colIndex == col-1) { // 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'
    			}
    		  }
    		})
    	  }
    	);
    });