Advanced Features

React Data GridCustom Functions

Enterprise

Custom formula functions let you extend the engine with domain-specific logic and reusable calculations.

Formula Functions API Copy Link

Custom functions are provided through the formulaFuncs grid option.

formulaFuncsCopy Link
FormulaFuncs
A map of 'function name' to 'function' for custom functions that are used for formulas.

Simple Example Copy Link

The example below registers CUSTOMSUM, which iterates over all values passed to the function (including ranges) and returns their sum.

const [columnDefs, setColumnDefs] = useState([
    { field: 'sales' },
    { field: 'calculated', allowFormula: true },
]);
const formulaFuncs = {
    CUSTOMSUM: {
        func: (params) => {
            let total = 0;
            for (const value of params.values) {
                total += value;
            }
            return total;
        },
    },
};

<AgGridReact
    columnDefs={columnDefs}
    formulaFuncs={formulaFuncs}
/>

Error Handling Copy Link

Your function should throw when arguments are invalid. Errors are surfaced in the grid and propagate through dependent formulas.

When a function (or a referenced cell) throws an error, the cell displays #ERROR! and hovering over the cell displays the thrown error message. Errors also propagate to dependent formula cells.

Complex Example Copy Link

This example shows COUNTEQ, which receives a range and a value and counts matches. It uses params.args to validate argument types and handle ranges explicitly.

Best Practices Copy Link

  • Validate argument counts and types early.
  • Prefer iterators (params.values) for large ranges to avoid unnecessary allocations.
  • Keep functions pure and fast to avoid performance issues on large grids.

See Formula Reference for built-in functions that can inspire custom implementations.