cancel
Showing results for 
Search instead for 
Did you mean: 

How do I pass the content of a text Input to a Blox filter?

irismaessen
9 - Travel Pro
9 - Travel Pro

I'm trying to create a slightly more restrictive text filter using Blox. I want my users to be able to type in a search term to filter on, but I only want them to be able to do a 'contains' filter, not the other free text filter options.

I've managed to get an inputbox that gathers text, and a button that applies a 'contains' filter. What I have not yet managed is to pass information from one to the other. I'm fairly new to BloX, so I'm probably missing something obvious

Snippet of what I've got so far -- this just filters the dashboards to values containing the literal string {New Input.textVal}

 

 

{
    "style": "",
    "script": "",
    "title": "",
    "showCarousel": true,
    "carouselAnimation": {
        "delay": 0,
        "showButtons": false
    },
    "body": [
        {
            "type": "Container",
            "items": [
                {
                    "type": "ColumnSet",
                    "columns": [
                        {
                            "type": "TextBlock",
                            "horizontalAlignment": "center",
                            "verticalContentAlignment": "center",
                            "wrap": true,
                            "text": "Search Text",
                            "spacing": "small"
                        },
                        {
                            "type": "Container",
                            "items": [
                                {
                                    "type": "Input.Text",
                                    "id": "textVal",
                                    "class": "",
                                    "title": "New Input",
                                    "placeholder": "Your Search Term",
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ],
    "actions": [
        {
            "type": "Filters",
            "title": "Filter (by Dimension)",
            "data": {
                "filters": [
                    {
                        "filterJaql": {
                            "contains": "{New Input.textVal}"
                        },
                        "dim": {
                            "title": "Search",
                            "table": "myTable",
                            "column": "myColumn",
                            "datatype": "text"
                        }
                    }
                ]
            }
        }
    ]
}

 

 

 

 

1 ACCEPTED SOLUTION

harikm007
12 - Data Integration
12 - Data Integration

Hi @irismaessen ,

Try this blox script (update table and column name in script):

{
    "style": "",
    "script": "",
    "title": "",
    "showCarousel": true,
    "carouselAnimation": {
        "delay": 0,
        "showButtons": false
    },
    "body": [
        {
            "type": "Container",
            "items": [
                {
                    "type": "ColumnSet",
                    "columns": [
                        {
                            "type": "TextBlock",
                            "horizontalAlignment": "center",
                            "verticalContentAlignment": "center",
                            "wrap": true,
                            "text": "Search Text",
                            "spacing": "small"
                        },
                        {
                            "type": "Container",
                            "items": [
                                {
                                    "type": "Input.Text",
                                    "id": "data.filters[0].filterJaql.contains",
                                    "class": "",
                                    "title": "New Input",
                                    "placeholder": "Your Search Term"
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ],
    "actions": [
        {
            "type": "Filters",
            "title": "Filter (by Dimension)",
            "data": {
                "filters": [
                    {
                        "filterJaql": {
                            "contains": ""
                        },
                        "dim": {
                            "title": "Search",
                            "table": "Records",
                            "column": "Region",
                            "datatype": "text"
                        }
                    }
                ]
            }
        }
    ]
}

-Hari

View solution in original post

7 REPLIES 7

devanisetty
7 - Data Storage
7 - Data Storage

Hi Iris, 

Below is the widget level script (which need to be added in Blox widget scripts). 

 

widget.on('ready', function(w){ 

	$('#textVal').blur(function(){
		var applyJaql = {
			'jaql':{
				"table": "TableeName",
				"column": "TableName.ColumnName",
				"dim": "[TableName.ColumnName]",
				"datatype": "text",
				"title": "Your Search Term",
				"filter": {
					"multiSelection": false,
					'members': [$(this).val()],
                    'explicit': true
                }
			},
			'instanceid': 'filterInstanceID'  
		};
		prism.activeDashboard.filters.update(applyJaql,filterOptions);
		
		prism.activeDashboard.refresh();
	});

});
​

filterInstanceID - In the dashboard console type below line, in the console we will have the list of filters on the dashboard with instanceID

prism.activeDashboard.filters.$$items​

 

Hope the above solution works for your need. 
 
Thanks, 
Dev

Hi,

Thanks for replying. In extremis, this might give me some guide on how to achieve what I would like to do.


But why would I need to resort to Widget scripts for this if Blox allows interaction between actions and input elements in other cases? Surely there must be a way I can pass the value of the inputbox to the Blox filter action without having to use another widget script?

Rather in Widget Scripts, I think we can move the scripts to customAction and use it.

harikm007
12 - Data Integration
12 - Data Integration

Hi @irismaessen ,

Try this blox script (update table and column name in script):

{
    "style": "",
    "script": "",
    "title": "",
    "showCarousel": true,
    "carouselAnimation": {
        "delay": 0,
        "showButtons": false
    },
    "body": [
        {
            "type": "Container",
            "items": [
                {
                    "type": "ColumnSet",
                    "columns": [
                        {
                            "type": "TextBlock",
                            "horizontalAlignment": "center",
                            "verticalContentAlignment": "center",
                            "wrap": true,
                            "text": "Search Text",
                            "spacing": "small"
                        },
                        {
                            "type": "Container",
                            "items": [
                                {
                                    "type": "Input.Text",
                                    "id": "data.filters[0].filterJaql.contains",
                                    "class": "",
                                    "title": "New Input",
                                    "placeholder": "Your Search Term"
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ],
    "actions": [
        {
            "type": "Filters",
            "title": "Filter (by Dimension)",
            "data": {
                "filters": [
                    {
                        "filterJaql": {
                            "contains": ""
                        },
                        "dim": {
                            "title": "Search",
                            "table": "Records",
                            "column": "Region",
                            "datatype": "text"
                        }
                    }
                ]
            }
        }
    ]
}

-Hari

That works! Fantastic! Thank you!

Now to see if I can show what the filtered value *is* once the filter has been applied but I think I saw some examples floating around for that somewhere.

(And, for my own understanding... why does it work?)

harikm007
12 - Data Integration
12 - Data Integration

I added one more line in the script which connects text box with filter action 

 "id": "data.filters[0].filterJaql.contains"

 -Hari

That's the only thing I actually changed in my own script to make it work, yes. 
I'm wondering how giving a div an id that references a filter jaql passes the value to that filter jaql.

Probably it's not actually a div and I'm misinterpreting what I'm seeing in BloX -- I'm more comfortable with data modeling and formulas than with JS and CSS/HTML 🙂

Thank you again!