# Dashboard Filters Object

Available via dashboard.filters. Represents the Dashboard's filters, and provides methods to access & modify them.

# Properties

Name Type Description
length integer How many filters exist in the dashboard
$$items MetadataItem[] A read-only array of existing filters

# Methods

# item

Fetch a filter from the Dashboard by index or dimension

# Get filter by index

filters.item(index)

Arguments

Name Type Required Description
index integer Yes Index of filter to fetch

Returns

MetadataItem

Example

console.log(dashboard.filters.item(0));

# Get filter by dimension

filters.item(dimension[, level])

Arguments

Name Type Required Description
dimension string Yes Dimension name to fetch filter for
level string No Dimension level - only applicable to date filters

Returns

MetadataItem

Example

console.log(dashboard.filters.item('[Sales.SaleDate (Calendar)]', 'years'));

# update

filters.update(filter, options)

Adds or updates the filter object matching the dimensions and level of the given filter.

If the provided filter's dimension already exists in the Dashboard, it will be updated. Otherwise, a new filter will be appended to the end of the Dashboard's filters array.

Arguments

Name Type Required Description
filter MetadataItem Yes Filter object to add or update
options object Yes See below
options.refresh boolean Yes Should the Dashboard refresh after the change
options.save boolean Yes Should the change be saved to the server

Returns

N/A

Example

// Add a new filter temporarily (without saving)
dashboard.filters.update(newFilter, { refresh: true, save: false });

# remove

Remove a filter from the Dashboard by index or dimension.

Cascading filters

Note that the .remove() method cannot be used to remove cascading/dependent filters.

# Remove filter by index

filters.remove(index)

Arguments

Name Type Required Description
index integer Yes Index of filter to remove

Returns

MetadataItem

Example

dashboard.filters.remove(0);

# Remove filter by dimension

filters.remove(dimension[, level])

Arguments

Name Type Required Description
dimension string Yes Dimension name to remove filter by
level string No Dimension level - only applicable to date filters

Returns

MetadataItem

Example

dashboard.filters.remove('[Sales.SaleDate (Calendar)]', 'years');

# clear

filters.clear()

Removes all items from the filters collection.

Arguments

N/A

Returns

N/A

Example

dashboard.filters.clear();

# insert

filters.insert(filter[, index])

Inserts a new filter to the Dashboard's filters array at the provided index, similar to a splice operation.

If index is undefined, the filter will be appended to the end of the array.

Arguments

Name Type Required Description
filter MetadataItem Yes Filter object to add
index integer No Index to insert to

Returns

N/A

Example

dashboard.filters.insert(newFilter, 2);

# reorderItem

filters.reorderItem(sourceIndex, targetIndex)

Moves a filter item from the sourceIndex to the tagetIndex position in the Dashboard filters array.

Arguments

Name Type Required Description
sourceIndex integer Yes Index to move item from
targetIndex integer Yes Index to move item to

Returns

N/A

Example

dashboard.filters.reorderItem(2, 4);