Header Predicates

Predicates allow you to create a match between elements (for example, a measure header item or an attribute header item) with an arbitrary level of complexity. The predicates are used in drilling so that you can decide which parts of your visualization can be drilled into.

A header predicate is a function returning a boolean value that takes two arguments:

  • Mapping Header is an object that describes the item whose match is being tested (for more details, see the definition).

  • Header Predicate Context is additional data that describes the context in which the match is being tested: the data view that resulted in the values passed as the first argument (for more details, see the definition).

If the predicate returns true for an item, the item is matched.

The most common predicates are predefined in HeaderPredicateFactory. You can also write your own predicates.

Examples of custom header predicates

Example: A predicate that matches all items with the names starting with a capital A

import { isResultAttributeHeader } from "@gooddata/sdk-model";

const startsWithA = (header) => {
    return isResultAttributeHeader(header) && header.attributeHeaderItem.name.startsWith("A");

Example: A predicate that matches only attribute headers and only if the visualization has up to three attributes

import { isAttributeDescriptor } from "@gooddata/sdk-model";

const attributesIfNoMoreThanThree = (header, context) => {
    if (context.dv.def().attributes().length > 3) {
        return false;

    return isAttributeDescriptor(header);