Code snippet for filtering with Javascript
Hi,
Here's an example of how to use a dashboard Javascript extension to add dashboard filters.
The following code adds a filter that removes all emails that contain "sisense" in them:
dashboard.filters.update({
jaql:{
dim:'[tracking.email]',
title:'Renamed Filter',//optional
filter:{
doesntContain:'yes'//members:["aaa@aaa.com"]
},
table:'tracking', //optional
column:'email' // optionaldatatype:"text" //mandatory
}
},{save:true, refresh:true, unionIfSameDimensionAndSameType:true})
in case you want to call this object from outside the dashboard, please replace
dashboard.filters.update(
with
prism.activeDashboard.filters.update(
-
what is the purpose of this?
I'm looking for a way to filter datas for different client by dates.
The only way for now is to create dashboards for each clients with a date filter in them.
Is there a way of creating a widget filter that will check for a date from a table and use this date depending on the login username ?
-
Hi,
This snippet seems to be for a whole dashboard filtering...
In V4, I was able to filter a specific widget using jaql.
//selection of the widget to filter
monPivot2Widget = args.widget.dashboard.findWidgets({title: 'Detail'})[0];
//construct filter members array
members = []; members.push("XXX); members.push("YYY);members.push("ZZZ);
dim = "CP.CP";
prism.WidgetClient.filter(monPivot2Widget, [{dim: dim, members: members}]);How can we do something equivalent in V5 ?
Cdlt,
Bertrand.
-
Hi Vincent,
It is possible with javascript extendability, please open a tickets. Thanks!
Hi miot,
in V5 you can filer specific widget using the following code snippet:
widget.metadata.panel('filters').items.push({
jaql : {
dim : "[v_F_SPENDING_PLANNING.DSC_COUNTRY_CODE]",
filter : {
members : ["US"]
},
datatype : "text"
}
})widget.refresh();
for date filter filter you need specifiy json date format "yyyy-dd-mmThh:mm:ss"
in addition there is not find widgets, but here is some code to find widgets with attributes:
function getWidget(dashboard,obj){
if(typeof obj !== "object") return
var keys = Object.keys(obj);
var widgets = $$get(dashboard,'widgets.$$widgets')
if(!keys || !keys.length || !widgets) return;
for(var i = widgets.length - 1; i >= 0 ; i--){
var success = 0;
for(var j = keys.length - 1; j >= 0; j--){
widgets[i][keys[j]] == obj[keys[j]] ? success++ : '';
}
if(success == keys.length) return widgets[i];
}
}you can use as follows:
getWidget(dashboard, {title:"pivot"});
getWidget(dashboard, {title:"pivot", type:"pivot"});
Please try it out and replay
-
If you are looking to remove a filter once you've added it in the example above use the following:
widget.metadata.panel('filters').items.splice(-1,1)
This will remove the filter you added that will be on the end of the array. This is useful if you want to change the filter frequently on the widget.
-
Thanks for this, it was very helpful!
Do you happen to have an example of using the dashboard.filters.reset() method? I've tried executing this before running dashboard.filters.update, because I don't want to add to the members in the filter but rather overwrite them. However, I am getting the following error when I attempt to call the method:
Uncaught unsupported filter item selector
My call is like this:
var filter1 = dashboard.filters.item(0);
var filter2 = dashboard.filters.item(1);
console.log(filter1);
console.log(filter2);
dashboard.filters.reset([filter1, filter2]);Any help would be greatly appreciated! The documentation for this is pretty lacking, and doesn't include and sample calls: http://developer.sisense.com/display/API2/JavaScript+API+Reference#JavaScriptAPIReference-dashboardFiltersClassdashboardFiltersClass
-
Hi team,
I am also facing unsupported filter item selector issue while performing reset as per below syntax taken from the source url
reset
filters ( [jaql] ) filters with which to reset the collection
-
Removes all filters and resets the filters collection with the given filters array.
-
Hello team,
It has been awhile for posts to happen in this thread, but I am attempting to create a dash board filter that dynamically adjusts with the current date.
Essentially we have a 'DimDate' filter set to 'This Quarter' within our dash board which works great, but whenever we enter into the last month of a given sales quarter, we need the 'DimDate' filter to be automatically set to 'Next Quarter' (this is due to the way our marketing team operates).
I'll post my code here, I am extremely new to Javascript, so please excuse the high likely hood of mistakes but any help will be much appreciated. Thank you!
---------------
dashboard.filters.update({
jaql:{
dim:’[dimDate.Date]’,
title:’Date’,
filter:{
equals : date
},
datatype:"timestamp"
}
},{save:true, refresh:true, unionIfSameDimensionAndSameType:true})
var d = new Date();
var n = date.getMonth();
If (n = 3) {
name = ‘Next Quarter’
} else if (n =6) {
name = ‘Next Quarter’
} else if (n =9) {
name = ‘Next Quarter’
} else if (n =12) {
name = ‘Next Quarter’
} else [
name = ‘This Quarter’
}
Please sign in to leave a comment.
Comments
10 comments