Skip to content

Formula

FormulaPlugin

The FormulaPlugin is a RevoGrid plugin that enables spreadsheet-like formula calculations within grid cells. Leveraging the “formulajs” library, this plugin allows users to input and compute formulas similar to those in Excel, such as “=SUM(A1:B2)”.

Key Features:

  • Formula Evaluation: Listens to the beforecellrender event to identify and calculate cell values that are formulas. The computed result replaces the formula as the cell’s display value.
  • Recursive Formula Support: Handles nested formulas by evaluating inner formulas first, ensuring accurate calculations even when formulas reference other formulas.
  • Error Handling: Detects and prevents recursive loops in formulas, returning a FORMULA_ERROR when recursion is detected to avoid infinite loops.
  • Data Integration: Utilizes grid data sources and column information to accurately resolve cell references within formulas.

Usage:

  • Integrate FormulaPlugin in the RevoGrid to enable formula parsing and computation. This is done by adding the plugin to the grid’s plugin list, allowing it to automatically handle formula cells during rendering.

Example

import { FormulaPlugin } from '@revolist/revogrid-pro';
const grid = document.createElement('revo-grid');
grid.plugins = [FormulaPlugin];

This plugin is essential for users who require dynamic data computations directly within their data grid, providing a powerful tool for real-time data analysis and presentation.

class FormulaPlugin {}

evaluate

export function evaluate(
formulaValue: string,
getCellValueByAddress: (col: number, row: number) => any
);

evaluateRawValuesFormula

Evaluates a formula before exporting to Excel, returning its computed value.

export function evaluateRawValuesFormula(formula: string, allSources: DataType[], columns: ColumnRegular[]);

FORMULA_PREFIX

FORMULA_PREFIX: string;

FORMULA_ERROR

FORMULA_ERROR: string;

parseFormula

parseFormula: (formula: string, getCellValueByAddress: (col: number, row: number) => any) => string;

isFormula

isFormula: (value?: any) => any;