Editing a Filter

A filter is a piece of JavaScript code that takes the value of a metric or property as input and produces a number (e.g. 2 decimal format), string (e.g. integer to label), or an HTML fragment (e.g. colored icon). It is loaded into the Servitly front-end and executed directly in the user's browser.

The filter output is attached to HTML so you can also generate an HTML fragment, for instance to style and color values.

The following code describe a filter that receives a number (float or string) and truncates decimals to 1 digit.

exports.singleDecimalFormat = function () {

    function SingleDecimalFormat() {}

    SingleDecimalFormat.prototype.transform = function (value, args) {

        return parseFloat(value).toFixed(1);
    };

    return SingleDecimalFormat;

}();

When writing code for your filter, you can use the following objects already available in the context:

  • appUtils: an object providing a set of methods to access and interact with the page.

  • servitlyClient: an object providing methods to access the Servitly backend API.