Like what you see? Have a play with our trial version.

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Corrected error in setPossibleValues code.

Table of Contents
maxLevel54
classcontents

Filter Object

A filter object represents an individual filter. It can be fetched using the getFilter function in the FiltersAPI Filters API.

It has a number of properties, listeners and functions that allow developers to create code that manipulates the filter and reacts to events that happen on the filter itself. 

...

If the filter option “Value Entry Method” is set to “Value List Selection”, as shown below.
Image Modified

In this case, Yellowfin will attempt to generate possible values for the filter. These values can be retrieved from Reference Code Values, Cached Values or a Custom Query. 

...

This property will only return anything values in cases where the filter property “Value Entry Method” is set to “Value List Selection” when creating the filter. If this is set to anything other than “Value List Selection” this property will return null.

...

let filter = filters.getFilter('Average Age at Camp');
filter.setValueTwo(35, true); //Set valueTwo and apply it
console.log(filter.appliedValueOne); //Outputs '35' 


appliedValueTwo

Returns

String or Number.

Description

...

The filter Athlete Country has the default values of [‘AU’, ‘NZ’]

filter.setValue(['UK', 'US']);

console.log(filter.values); //Outputs {valueList: ['UK', 'US'] }

filter.reset();

console.log(filter.values); //Outputs {valueList: ['AU', 'NZ']


clear(apply)

Returns

Nothing.

...

The filter Athlete Country has the default values of [‘AU’, ‘NZ’]

filter.setValue(['UK', 'US']);

console.log(filter.values); //Outputs {valueList: ['UK', 'US'] }

filter.clear();

console.log(filter.values); //Outputs {valueList: null]}


resetToLastAppliedState()

...

apply - Boolean - Default: false

Example

filter.setValueOne('Relaxation'); //Change the value to Relaxtion but don't immediately run the report

console.log(filter.valueOne); //Should return 'Relaxation'




setValueTwo(value, apply)

Returns

Nothing.

Description

...

Null is allowed as a value, from a user perspective this would just be clearing valueOnevalueTwo.

If setValueTwo is called when using an operator that isn’t Between or Not Between this function call will do nothing.

...

apply - Boolean - Default: false

Example

//Filter is a between filter (Average Age at Camp)
filter.setValueOne(15);
filter.setValueTwo(35);

console.log(filter.valueOne + " to " + filter.valueTwo); //Should output "15 to 35"



setValueList(valueList, apply)

...

If this is used on a single value operator, then it will take valueOne will be set to the first value of in the array and apply that to valueOne.

If this is called on a filter with a between operator. The , valueOne will be set to the first value of in the array and valueTwo will be set to valueOne and the second will be set to valueTwovalue in the array.

Parameters

valueList - Array

...

A list filter will treat this as you selecting a single value. It is equivalent to calling:

filter.setValueList(['single value']);


A between or single entry filter will set valueOne to the passed value. Effectively this:

...

Copies the filter's currently staged values, valueOne, valueTwo and valueList to the applied equivalents of those objects. If there are any changes between valueOne and appliedValueOne, valueTwo and appliedValueTwo and valueList and appliedValueList, an ‘applied’ event will be triggered with the values that have changed. See applied event for details. 

Example

Apply the value Adventure to the Demographic filter.

...

let possibleValues = filter.possibleValues;
possibleValues.push({
    value: 'Relaxation',
    description: 'Relaxation'
});
filter.setPossibleValues(possibleValues = possibleValues);


Override the entire possible values array with values of your own:

let possibleValues = [];
possibleValues.push({
    value: 'FIRST', //The data that is stored in the table for this filter is upper case.
    description: 'First' //Upper case can be painful to read, so put a more readable version to be displayed in the description
});

possibleValues.push({
  value: 'SECOND',
  description: 'Second'
});

filter.setPossibleValues(possibleValues = possibleValues);

Notes/Limitations

If the filter is part of a filter hierarchy any values you set through this property will be overwritten when the parent filter changes and pushes new values into this filter. 

...

When an event is set up a unique ID is assigned to it which is returned as the result of this function. This ID can be used by the removeEventListener function to remove the callback when you are done with it. If you are writing an application that requires loading and unloading reports it is recommended that you keep track of these listenerIds so that you can remove them when no longer needed.

See the event reference section for details about the events that this API will trigger itself.

...

let eventListenerId = filter.addEventListener('changed', function(event) {
    console.log(event.filter.name ' changed value');
    filter.removeEventListener(eventListenerId);
});

...

let eventListenerId = filters.addEventListener('changed', function(event) {
    console.log('One of my filters changed');
    filters.removeEventListener(eventListenerId);
});



trigger(eventName, eventData)

Returns

Nothing.

Description

...

Any event that is triggered through the FilterObject will have an object that contains the filterUUID and the filter object itself. 

filter.addEventListener('changed', function(event) {
      console.log(event.uuid); //The filters UUID that the event was triggered from
      console.log(event.filter);//The FilterObject that the event was triggered from
});


changed

Description

Occurs when any of the filter values changes. Triggers with an object that contains the values that changed as well as the previous values of all of those values.

Parameters

Event - Object

Contains:

  • uuid - String - UUID of the filter that triggered the event.
  • filter - FilterObject - FilterObject of the filter that triggered the event.
  • changed - Object - Object containing any values that have changed. Could possibly contain valueOne, valueTwo or valueList.
  • Previous - Object - Object containing the old values of all of the changed values. Could possibly contain valueOne, valueTwo or valueList.
Example

filter.addEventListener('applied', function(event) {
      console.log(event.filter.name + " has just been applied with the following changed values " + JSON.stringify(event.changed));
});

Anchor
appliedevent
appliedevent

applied

Description

Occurs when the filter is applied to the linked piece of content (report/dashboard). And the applied values change.

Parameters

Event - Object

Contains:

  • uuid - String - UUID of the filter that triggered the event.
  • filter - FilterObject - FilterObject of the filter that triggered the event.
  • changed - Object - Object containing any values that have changed. Could possibly contain valueOne, valueTwo or valueList.
  • Previous - Object - Object containing the old values of all of the changed values. Could possibly contain valueOne, valueTwo or valueList.
Example 

filter.addEventListener('applied', function(event) {
      console.log(event.filter.name + " has just been applied with the following changed values " + JSON.stringify(event.changed));
});

Notes/Limitations

The applied event may be triggered in a case like this:

let filter = filters.getFilter('Demographic');
filter.setValue(['Adventure']);
filter.apply();

filter.setValue(['Adventure']);
filter.apply();

Due to the code creating a new Array when calling setValue. So any comparison that occurs will be of Array to Array.

The correct values will still be applied to the report.


reset

Description

Occurs when the reset function is called on the filter. This can occur from user interaction, clicking the reset button on a filter menu, or by a developer explicitly calling it. 

Example 

filter.addEventListener('reset', function(event) {
      console.log(event.filter.name + " has just been reset");
});

Parameters

Event - Object

Contains:

  • uuid - String - UUID of the filter that triggered the event.
  • filter - FilterObject - FilterObject of the filter that triggered the event.



cleared

Description

Occurs when the clear function is called on the filter. This can occur from user interaction, or by a developer explicitly calling it. 

Difference between cleared and reset

Resetting a filter resets it to its default values. Where as clearing a filter will set it to have no values. 

Parameters

Event - Object

Contains:

  • uuid - String - UUID of the filter that triggered the event.
  • filter - FilterObject - FilterObject of the filter that triggered the event.
Example 

filter.addEventListener(cleared, function(event) {
      console.log(event.filter.name + " has just had its values cleared");
});