Code snippet for filtering with Javascript

Comments

10 comments

  • Avatar
    Vincent

    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 ? 

    0
    Comment actions Permalink
  • Avatar
    miot

    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.

    0
    Comment actions Permalink
  • Avatar
    miot

    Nobody can help on this ?

    0
    Comment actions Permalink
  • Avatar
    Vincent

    no ... i can't sorry !

    Only admins could help !

    0
    Comment actions Permalink
  • Avatar
    Eli

    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

     

    0
    Comment actions Permalink
  • Avatar
    miot

    Hi,

    Thank You, It's working.

    Cdlt,

    Bertrand (MIOT)

    0
    Comment actions Permalink
  • Avatar
    Nicholas Ranum

    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.

    0
    Comment actions Permalink
  • Avatar
    Alex Placito

    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

    0
    Comment actions Permalink
  • Avatar
    Siva

    Hi team,

    I am also facing unsupported filter item selector issue while performing reset as per below syntax taken from the source url 

    https://developer.sisense.com/display/API2/JavaScript+API+Reference#JavaScriptAPIReference-dashboardFiltersClassdashboardFiltersClass

     

    reset

    filters ( [jaql) filters with which to reset the collection

    -

    Removes all filters and resets the filters collection with the given filters array.

    0
    Comment actions Permalink
  • Avatar
    Bill Marty

    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’

    }

    0
    Comment actions Permalink

Please sign in to leave a comment.