How to Create BloX Custom 'From-To' Filter -- All Dates with “Clear” Button
Updated 01-21-2025
Astroraf thanks for the clarification. Please try to use the action code below. It worked for me and the dates did not reset with the page refresh.
const filVal_from = payload.data.SelectVal_from
const filVal_to = payload.data.SelectVal_to
const filterDims = payload.data.FilterFields;
const dash = payload.widget.dashboard;
let newFilter = {};
newFilter = {
jaql: {
dim: "",
filter: {
from: filVal_from,
to: filVal_to
}
}
};
filterDims.forEach(function (dim) {
newFilter.jaql.dim = dim;
dash.filters.update(newFilter, { refresh: true, save: true })
})
And also add this script to the widget:
widget.on('ready', function() {
// replace with filter name
var filterName = "Days in Date";
// ----------Find date filter----------
let dateFilter = dashboard.filters.$$items.find((item) => {
if (item.jaql && item.jaql.title.indexOf(filterName) !== -1) {
return true
}
})
// ----------Set selected 'from' value as placeholder for input field----------
var checkInvalid_from = typeof dateFilter.jaql.filter.from == 'undefined' || dateFilter.disabled== true;
//console.log(dateFilter.jaql.filter.from)
var filterValue_from = (checkInvalid_from) ? 'date' : dateFilter.jaql.filter.from;
//Set selected 'from' value as placeholder and default value for input field
//$('#SelectVal_from', element).attr('placeholder', filterValue_from);
$('#SelectVal_from', element).attr('value', filterValue_from);
// ----------Set selected 'to' value as placeholder for input field----------
var checkInvalid_to = typeof dateFilter.jaql.filter.to == 'undefined' || dateFilter.disabled== true;
//console.log(dateFilter.jaql.filter.to)
var filterValue_to = (checkInvalid_to) ? 'date' : dateFilter.jaql.filter.to;
//Set selected 'to' value as placeholder and default value for input field
//$('#SelectVal_to', element).attr('placeholder', filterValue_to);
$('#SelectVal_to', element).attr('value', filterValue_to);
});
Best Regards, Lily