Initialization Option Reports API

displayNameListener

Callback function used in some reports (notably, Large Group Report) to map raw names and identifiers in the report data to friendly display names at runtime.

This function is called whenever there are 1 or more raw values used in the report that can be replaced, with the list of raw values (in no particular order) given as the only argument. The return value should be an array of replacement names corresponding to each raw value.

Examples

displayNameListener: function (originalNames) {
    // A sample mapping of possible raw data values from the report
    // and their corresponding display names. This example is for
    // an aggregate report, where the group names from the dataset
    // may match the keys below:
    var displayNameMap = {
        "us": "United States",
        "cn": "China",
        "gb": "Great Britain",
        "au": "Australia",
        "us-ma": "Massachusetts",
        "cn-11": "Beijing Municipality",
        "gb-eng": "England",
        "au-nsw": "New South Wales",
        "school_1": "Massachusetts Institute of Technology",
        "school_2": "Peking University",
        "school_3": "University of Oxford",
        "school_4": "University of New South Wales"
        // Include as many display name associations as desired
        // ...
    };

    var displayNames = [];
    for (var i = 0; i < originalNames.length; i++) {
        var originalName = originalNames[i];
        if (originalName in displayNameMap) {
            // The mapped value is what will be displayed
            // instead of the corresponding original name
            displayNames.push(displayNameMap[originalName]);
        } else {
            displayNames.push(originalName);
        }
    }

    return displayNames;
}

Values

Type function

Callback arguments

The callback receives the following arguments when it is executed.

  • originalNames array[string]

    A list of raw names/values in the report that can be remapped for display using this callback; e.g. ["school_1", "school_2", "school_3"]. The possible values varies depending on the type of report and the report data.

Was this article helpful?