Knowledge Base Article

Change the background color of the Pivot cell on value Windows

Change the background color of the Pivot cell on value Windows

If you want to change the background color for categories on value, like in the picture below

 
You can use such a script:

 

var columns = [2]; //select the date columns that should be transformed

widget.on('ready', function (se, ev) {
	$.each(columns, function (index, value) {
		var num = $("tbody tr:first", element).children().length - value;

		$("tbody tr", element).not('.wrapper, .p-head-content').each(function () {
			var cell = $(this).children().last();
			for (var a = 0; a < num; a++) {
				cell = cell.prev();
			}

			var cell_value = cell.text()
// change the values and color below
			if (cell_value.includes('Male')) {
				$(cell).css("background-color", 'red');
			} else if (cell_value.includes('Female')) {
				$(cell).css("background-color", 'yellow');
			}else if (cell_value.includes('Unspecified')) {
				$(cell).css("background-color", 'white');
			}
		});
	});
});

 


For your Pivot widget, press the Edit button in the upper right corner of the widget (pencil icon), press the three dots in the upper right corner, select Edit Script from the menu, and paste the code. Then press the Save button.

Have a good day!

Disclaimer: This post outlines a potential custom workaround for specific use cases. The solution may not work in all scenarios or Sisense versions, so we strongly recommend testing it in your environment before deployment. The content is provided "as-is" without any warranty, including security or fitness for a particular purpose. Custom coding is involved, which falls outside Sisense's warranty and support.

Additional Resources:

Sisense Academy: https://academy.sisense.com/master-class-advanced-dashboards-with-plug-ins-and-scripts

Sisense Docs: https://docs.sisense.com/main/SisenseLinux/customizing-sisense-using-code.htm

Sisense Community: https://community.sisense.com/t5/forums/searchpage/tab/message?q=widget%20scripts

Updated 11-19-2024
No CommentsBe the first to comment