top of page

Blox drop-down v2 - Without 'Apply' button

We know its possible to create a dropdown using blox. But it requires a button to apply the filter to dashboard. Here is a solution to create blox dropdown without a button. Filter will get applied as soon as the user selects an item from dropdown.



Steps:

  1. Create new Blox widget and add a dimension under 'items' panel. Add same dimension as a dashboard filter.



2. Add below Blox script. Replace the name 'Region' in below script with the name of dimension you added in the above step.



{
    "style": "select {border-radius:5px}",
    "script": "",
    "title": "",
    "titleStyle": [
        {
            "display": true
        }
    ],
    "showCarousel": true,
    "carouselAnimation": {
        "showButtons": false
    },
    "body": [
        {
            "type": "Container"
        },
        {
            "type": "ColumnSet",
            "separator": false,
            "spacing": "default",
            "columns": [
                {
                    "type": "Column",
                    "spacing": "none",
                    "width": "250px",
                    "items": [
                        {
                            "type": "Container",
                            "spacing": "none",
                            "width": "220px",
                            "height": "50px",
                            "style": {
                                "color": "black",
                                "padding-top": "10px",
                                "margin-left": "10px",
                                "backgroundColor": "white"
                            },
                            "items": [
                                {
                                    "type": "Input.ChoiceSet",
                                    "id": "data.filters[0].filterJaql.members[0]",
                                    "class": "dropdownChoices",
                                    "value": "Reseller",
                                    "displayType": "compact",
                                    "choices": "{choices:Region}",
                                    "style": {
                                        "color": "#656566",
                                        "padding-left": "10px",
                                        "margin-left": "10px",
                                        "backgroundColor": "grey",
                                        "border": "2px solid #aac7e6",
                                        "height": "35px",
                                        "font-size": "15px"
                                    }
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ],
    "actions": []
}



3. Add below widget script. This is to add 'All' in dropdown and apply filter as son as user picks an item



widget.on('processresult', function(se, ev){
	allObject = [{
					"Panel": "Region",
					"Value": "All",
					"Text": "All",
					"HasValue": true
				}]
	
	ev.result.unshift(allObject)
})

widget.on('ready', function(se, ev){
	
	var filterName = 'Region'
	
	var select = document.getElementById(`data.filters[0].filterJaql.members[0]`);
	
	dashboardFilter = prism.activeDashboard.filters.$$items.find(el => el.jaql.title == filterName)
	
	if(dashboardFilter && dashboardFilter.jaql.filter && dashboardFilter.jaql.filter.members)
	{
		select.value = dashboardFilter.jaql.filter.members[0]
	
	}
	
	select.addEventListener("change", function(e){ 

		if(e.target.value == "All")
		{
			filter = {
				"explicit": false,
				"multiSelection": true,
				"all": true
			}
		}else
		{
			filter = {
				"explicit": true,
				"multiSelection": true,
				"members": [
					e.target.value
				]
			}
		}

		dashboardFilter = prism.activeDashboard.filters.$$items.find(el => el.jaql.title == filterName)

		var filterOptions = {
			save: true,
			refresh: true,
		}
		dashboardFilter.jaql.filter = filter
		prism.activeDashboard.filters.update(dashboardFilter, filterOptions)
	
	});

})



850 views3 comments

3 comentários

Avaliado com 0 de 5 estrelas.
Ainda sem avaliações

Adicione uma avaliação
MARIA1986
02 de mar. de 2024

Is it possible to only view items with applied filters at widget level? Currently it is showing all data from the selected column, however I only want the items to show that I have selected at widget level.

Editado
Curtir

Prakash Periasamy
Prakash Periasamy
08 de mar. de 2023

Hi

This script and tip works great on one filter field. But if I like to implement several drop down filter fields, it isn't working. Not sure if I need to edit the id `data.filters[0].filterJaql.members[0]` accordingly for different filters fields. For example, in my dashboard pane if I have 10 filters and I like to implement 4 of those filters as dropdown filters without `Apply` button. As-is, the code works great if I have setup one dropdown filter for a field say "Field A". But when I add the next dropdown filter for the second field say "Field B", then it breaks. Either the filter doesn't gets applied at all for Field B or sometimes the selection in Field…

Curtir
BI Next Level
BI Next Level
14 de mar. de 2023
Respondendo a

You are right, you need to use a different Id for each dropdown and update the script to use that id in each widget

Curtir
BI Next Level white logo

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
Copyright © 2024. All Rights Reserved. Designed, Developed & Maintained  by Intertoons
bottom of page