Formula

The Formula widget empowers users to craft tailored calculations by harnessing JavaScript formulas within their application interface

Specs

Label
Value

Version

1.2.0 (updated on 2024-02-27)

Developer

Labii Inc.

Type

Column

Support Configuration

Yes

Support Readonly view

Yes

Support Edit view

No

Support Form view

No

Support Default value

No

Support Import

No

Allow multiple

Yes

Overview

The Formula widget empowers users to craft tailored calculations by harnessing JavaScript formulas within their application interface. This dynamic tool seamlessly integrates with data from the current record, facilitating precise calculations that reflect specific context. Furthermore, its functionality extends to encompass values sourced from related records via ForeignKey relationships, granting users unparalleled flexibility in constructing comprehensive calculations that span across data sets. Whether crafting intricate financial models or refining data analysis, the Formula widget offers a versatile solution for users seeking to harness the power of custom calculations within their application workflows.

Use case

  • Calculate the volume left for a sample.

  • Calculate the detection status for RT-PCR results.

Configuration

To enable the widget's functionality, it requires the provision of options.

  • Source columns - To define the data source, select one of the ForeignKey, ForeignKeys, or NestedFields columns.

  • Query - Provide one or more queries for the count value if you wish to use it in the formula.

  • Formula - Syntax: data[Field 1] + data[Field 2] + count[query name]

  • Execute after - Select the formula columns that need to be executed before this formula is triggered. When a formula is based on a value generated by another formula, this field should be used.

  • Should auto update - If checked, this widget will perform a live calculation.

  • Should auto update when empty - If checked, this widget will perform a live calculation when empty.

Example

{
    "columns": [ # (optional), 
        {"sid":"xxx", "name":"xxx"}, # The column sid of ForeignKey, ForeignKeys, NestedFields, optional
    ], 
    "queries": [ # (optional)
        {
            "name": "xxx",
            "table": {"sid":"xxx", "name":"xxx"},
            "query": "name=xxx"
        }
    ], 
    "formula": "", # (required), the formula, see the Syntax below
    # data[column_sid], value of a column of current row
    # data[row_sid__column_sid], value of column of a fixed row
    # data[`${data['column__sid'].sid}`__column_sid]
    # data[column1_sid__column2_sid], column1_sid, the ForeignKey column listed in rows; 
    # data[column1_sid__column2_sid] of ForeignKeys returns array of data.
    # count[table_sid__column_sid], the count value
    "after": [], # Select the formula columns that need to be executed before this formula is triggered. 
    # When a formula is based on a value generated by another formula, this field should be used.
    "format": {}, # (optional), the number in the wNumb format. 
    # Learn more at https://refreshless.com/wnumb/
    "should_auto_update": false, # (optional), default to false. 
    # If true, the widget will perform live calculation
    # If false, the user have to click reload to update the value
    "should_auto_update_when_empty": true, # (optional), default to true. 
    # If true, the widget will perform live calculation when the data is empty
    # If false, the results will not be calculated on default
}

Use formula to return record name

formula = `return "{{NAME}}"`

Views

See the interface of the widget in the following views.

Readonly view

Readonly view display the values of the column.

Edit view

The Edit view is the interface that allows you to modify the value.

Edit view is not supported for this widget.

Form view

The Form view is the field integrated into the add form for collecting values when creating a new record.

Form view is not supported for this widget.

Data

Each widget in Labii stores data in a unique manner; refer below to understand how data from this widget is stored.

Data format

Any data return from the formula.

Default value

The Default Value field within the column allows you to specify the default value when a record is created.

Default value is not supported for this widget.

Import value

The Import Value is the value you need to include in your Excel table for it to be imported into Labii.

Import value is not supported for this widget.

Last updated