displayNameListener - Initialization - Reports API

Reports API Initialization

displayNameListener()

Maps raw names and identifiers in the report data to user friendly display names at runtime.

You would want to use this to replace internal code names with user friendly names.

This callback function only runs for certain reports, notably the Large Group Report.

Examples

var callbacks = {
    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",
            "school_1": "Massachusetts Institute of Technology",
            "school_2": "Peking University",
            "school_3": "University of Oxford"
        };

        // Replace with user friendly names
        var displayNames = [];
        for (var i = 0; i < originalNames.length; i++) {
            var originalName = originalNames[i];
            if (displayNameMap[originalName]) {
                // Replace the name if found
                displayNames.push(displayNameMap[originalName]);
            } else {
                // Keep the original display name when not found
                displayNames.push(originalName);
            }
        }

        // Return the new names back to the report for rendering
        return displayNames;
    }
};

Arguments

  • originalNames array[string]

    A list of original names in the report that can be remapped using this callback.

Return value

None (undefined).

Was this article helpful?

Did you arrive here by accident? If so, learn more about Learnosity.