top of page

Hide a Column from Table Widget

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:

  1. Create a table widget

  2. 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)

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


157 views0 comments

Recent Posts

See All
bottom of page