Sometimes we may need to hide a column from table widget, so that it will appear only in the downloaded CSV file. Here is a solution to achieve this.
Steps:
Create a table widget
Add below widget script. Update the variable columnIndex with index of column to be hidden. (index is a number assigned to columns starting with 1. In above screenshot, State column has index 1, Country has index 2 and Region has index 3)
Save the script and refresh the dashboard
widget.on('domready', function(se, ev){
let columnIndex = 3
$(`table tr > *:nth-child(${columnIndex})`, element).css('display', 'none')
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){
$(value).find(`td:nth-child(${columnIndex})`).css('display', 'none')
})
}
}
})
observer.observe(elementToObserve, {subtree: true, childList: true});
})
how do you take this script and hide multiple columns?