top of page

Buttons to Sort bars/columns

Updated: Nov 27, 2024

Sorting is very simple in Sisense. But this option is accessible only by chart editors. We can add buttons to sort the chart by name or value using below script so that even viewers can sort the chart.


ree

Steps:

  1. Create a bar/column/line/area chart

  2. Add below script to widget

  3. Save the script and refresh the widget



widget.on('processresult', function(se, ev){	
	ev.result.chart.spacing = [60, 20, 20, 20]
});


widget.on("domready", function(w, args){
		
	chart = w.chart[0][Object.keys(w.chart[0])[0]].hc
		
	chart.renderer.button('Sort by Name - Asc', 10, 10)
		.attr({
			zIndex : 10,
			height: 15,
			width: 120,
			'text-align': 'center'
		})
		.on('click', function() {						
			widget.metadata.panels[1].items[0].jaql.sort = undefined
			widget.metadata.panels[0].items[0].jaql.sort = 'asc'
			
			widget.refresh();
		})
		.add();
	
	chart.renderer.button('Sort by Name - Desc', 150, 10)
		.attr({
			zIndex : 10,
			height: 15,
			width: 120,
			'text-align': 'center'
		})
		.on('click', function() {						
			widget.metadata.panels[1].items[0].jaql.sort = undefined
			widget.metadata.panels[0].items[0].jaql.sort = 'desc'
			widget.refresh();
		})
		.add();
	
	chart.renderer.button('Sort by Value - Asc', 290, 10)
		.attr({
			zIndex : 10,
			height: 15,
			width: 120,
			'text-align': 'center'
		})
		.on('click', function() {						
			widget.metadata.panels[1].items[0].jaql.sort = 'asc'
			widget.metadata.panels[0].items[0].jaql.sort = undefined
			widget.refresh();
		})
		.add();
	
	chart.renderer.button('Sort by Value - Desc', 430, 10)
		.attr({
			zIndex : 10,
			height: 15,
			width: 120,
			'text-align': 'center'
		})
		.on('click', function() {						
			widget.metadata.panels[1].items[0].jaql.sort = 'desc'
			widget.metadata.panels[0].items[0].jaql.sort = undefined
			widget.refresh();
		})
		.add();

});

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating

BI Next Level is your trusted resource for BI customization, data solutions, and expert insights. Explore practical tips, scripts, and tutorials for tools like Sisense, Python, and SQL. Let’s transform your data into impactful insights together.

Quick Links
Connect with us
bottom of page