cancel
Showing results for 
Search instead for 
Did you mean: 
Community_Admin
Community Team Member
Community Team Member

Question

I want to use the Date picker for filtering, however, the dates selected are not getting preserved by the date picker and might be confusing for the end users whether the date is selected or not.

Community_Admin_0-1634632200939.png

Answer

You can use the script to keep the selected values in the filter.

widget.on('ready',function(se,ev){

if (!Array.isArray(se.queryResult)) return;

var minMax = se.queryResult.reduce(function(acc, val){
if((!acc.min) || acc.min>val[0].Value){acc.min = val[0].Value}
if((!acc.max) || acc.max<val[0].Value){acc.max = val[0].Value}
return acc
} , {min:undefined,max:undefined})


formatted_dateFrom = moment(minMax.min).format('YYYY-MM-DD')
formatted_dateTo = moment(minMax.max).format('YYYY-MM-DD')

document.getElementById("data.filters[0].filterJaql.from").value=formatted_dateFrom
document.getElementById("data.filters[0].filterJaql.to").value=formatted_dateTo

document.getElementById("data.filters[0].filterJaql.from").setAttribute("style", "text-align:center");
document.getElementById("data.filters[0].filterJaql.to").setAttribute("style", "text-align:center");

})

This will pull the values for you.

Rate this article:
Comments
kreycraft
Sisense Team Member
Sisense Team Member

I've tried this as both a widget and dashboard script and it hasn't worked yet.  I'm missing the connection between date filter and populating the Blox widget. 

 

kreycraft_0-1648585191302.png

 

kenterickson
8 - Cloud Apps
8 - Cloud Apps

I'm having the same issue as @kreycraft - script doesn't seem to help.

kenterickson
8 - Cloud Apps
8 - Cloud Apps

@Community_Admin The  queryResult property returns an object, not an array.  Therefore, line 3 exits this script with nothing happening.

Jijish
8 - Cloud Apps
8 - Cloud Apps

Facing similar issues. Any inputs on how to solve this issue will be greatly appreciated

Martha
7 - Data Storage
7 - Data Storage

Hi,

I'm getting the current filter value as described in https://community.sisense.com/t5/knowledge-base/blox-date-and-timestamp-range-filter/ta-p/4973. This then worked for me:

//***** Populate input boxes with current filter values *****/
widget.on('ready', function() {
	
	//replace with filter name
	var filterName = "Date";

	// ----------Find date filter----------
    let dateFilter = dashboard.filters.$$items.find((item) => {
        if (item.jaql && item.jaql.title.indexOf(filterName) !== -1) {
            return true
        }
    })
		
	//get the current 'from' filter value
	var fromDate = dateFilter.jaql.filter.from;
	
	//get the current 'to' filter value
	var toDate = dateFilter.jaql.filter.to;

	//set the current 'from' and 'to' filter values as placeholder and default value for input field
	document.getElementById("data.filters[0].filterJaql.from").value=fromDate
	document.getElementById("data.filters[0].filterJaql.to").value=toDate
	
});

 

 

Version history
Last update:
‎10-19-2021 01:31 AM
Updated by:
Contributors