cancel
Showing results for 
Search instead for 
Did you mean: 

concat strings at the dashboard layer?

bminehart
10 - ETL
10 - ETL

In a table or pivot table widget I want to concatenate strings contained in two separate data model columns. Example: col1 contains "Abraham" and col2 contains "Lincoln". I want to concatenate them, along with a space to display "Abraham Lincoln" in another column

I know there is not a widget level function to do this. Would this be possible in a widget script? And if so - any idea how?

3 REPLIES 3

harikm007
13 - Data Warehouse
13 - Data Warehouse

Hi @bminehart ,

To concatenate columns in a table widget, try these steps:

  1. Add col1 and col2 to the table widget.
  2. Add the following widget script. Make sure to update the variables column1_index and column2_index with the respective indices of the two columns you want to concatenate. The script will display the concatenated string in the column with index column1_index and hide the column with index column2_index. 

 

const column1_index = 1;
const column2_index = 2;

widget.on('processresult', function(w, args){
	args.result.$$rows.forEach(item => {
		item[column1_index].text = `${item[column1_index].text} ${item[column2_index].text}`;
	})
})
//Refer:  https://www.binextlevel.com/post/hide-a-column-from-table-widget 
widget.on('domready', function(se, ev){
	
	
	$(`table tr > *:nth-child(${column2_index + 1})`, 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(${column2_index + 1})`).css('display', 'none')

				})
			}
		}
	})
										  
	observer.observe(elementToObserve, {subtree: true, childList: true});
	
})

 

3. Refresh the widget.

harikm007_0-1736401227444.png

For more details on how to hide a column in the table widget, refer to this post: https://www.binextlevel.com/post/hide-a-column-from-table-widget 

-Hari

bminehart
10 - ETL
10 - ETL

Thanks @harikm007 -- we'll give this a go and take a look at the blog posting.

bminehart
10 - ETL
10 - ETL

@harikm007 - success w/ a Table widget, but not Pivot Table. Would it be possible in the latter?