cancel
Showing results for 
Search instead for 
Did you mean: 

Sort BloX Widget Carousel by Value

jwoodard
8 - Cloud Apps
8 - Cloud Apps

I am looking to find a way to use a widget script to override the sort logic for a BloX Carousel. 

Use Case: I am displaying the Top 10 agents for a company and wish to sort by the production rank of the individuals as opposed to the alphabetical order of the agent's name. This would allow the user to always see the top ranked agent first and would progress to the 2nd ranked, 3rd ranked and so on. 

Other details: There is no need to update the sort order or switch the direction of the sort as the ranking would drive the experience so this solution could be hard-coded in the widget script. 

1 ACCEPTED SOLUTION

harikm007
13 - Data Warehouse
13 - Data Warehouse

Hope this script works. This is to sort blox by Values.  (here 2 is the index of Rank panel in your screenshot)


widget.on('queryend',function(se,ev){
	ev.rawResult.values.sort(function(a, b){
		var aValue = a[2].data;
		var bValue = b[2].data;
						
		if (aValue < bValue)
			return -1;
		if (aValue > bValue)
			return 1;
							
		return 0;
	})
})

 

 

Just curious to know - Does the value panel's sorting not work?

harikm007_0-1664539294550.png

-Hari

 

 

View solution in original post

4 REPLIES 4

harikm007
13 - Data Warehouse
13 - Data Warehouse

Hi @jwoodard ,

If there is only one dimension added under 'Items' panel (as Region in below screenshot), try this script:

 

var categories= ['South','West','Midwest','Unknown','Northeast'];


widget.on('queryend',function(se,ev){
	ev.rawResult.values.sort(function(a, b){
		var aIndex = categories.indexOf(a[0].data);
		var bIndex = categories.indexOf(b[0].data);
						
		if (aIndex < bIndex)
			return -1;
		if (aIndex > bIndex)
			return 1;
							
		return 0;
	})
})

harikm007_0-1664475517459.png

Related posts: 

https://www.binextlevel.com/post/sort-bar-columns-breakby-manually

https://www.binextlevel.com/post/sort-bar-column-line-chart-based-on-a-field-in-table

-Hari

 

Greetings Hari, 

Unfortunately, this solution does not solve for my specific use case. Providing a few more details and examples to hopefully help better explain from my end. 

 

I am using a BloX widget and have the carousel enabled "showCarousel": true  with two items (officeId & officeName). 

jwoodard_0-1664477280748.png

By default, the BloX widget sorts based on the items in alphabetical order. For example, the first result the carousel returns is "A Sample Office Name" though this office is ranked #8 in the top ten agencies. 

jwoodard_2-1664477452660.png

 

In order to see the #1 ranked item, the user must click through the results until they find the #1 ranked office. The rank data is coming from the values section shown in the first image. As the sorting of the carousel is based on the office information instead of the rank, the ranks are shuffled as the user clicks through the carousel. 

jwoodard_3-1664477695245.png

 

Our goal is to have the #1 ranked item (based on the values) first appear when the widget is loaded. The 2nd item should be the first item when the right carousel arrow is clicked, followed by the 3rd, and so on. The 10th ranked item should show when clicking the left carousel arrow when viewing the top ranked item. 

 

Hopefully this provides more clarity! 

 

Thanks, 

Jordan

 

 

harikm007
13 - Data Warehouse
13 - Data Warehouse

Hope this script works. This is to sort blox by Values.  (here 2 is the index of Rank panel in your screenshot)


widget.on('queryend',function(se,ev){
	ev.rawResult.values.sort(function(a, b){
		var aValue = a[2].data;
		var bValue = b[2].data;
						
		if (aValue < bValue)
			return -1;
		if (aValue > bValue)
			return 1;
							
		return 0;
	})
})

 

 

Just curious to know - Does the value panel's sorting not work?

harikm007_0-1664539294550.png

-Hari

 

 

Thanks Hari! 

Looks like I overcomplicated things and missed the easiest solution. The script will be useful in some other applications I'm working on implementing with BloX though so it is helpful to understand the calls provided.