Search code examples
ag-gridag-grid-angular

How to implement Excel formulas in AG-Grid table cells using angular


`I am trying to achieve calculation in AG-Grid cell like Excel, example in Excel we will try like blow =Sum(value1, value2). Same like i have to try in AG-Grid cell example when i typed expression starting with = sign that should be calculate based on given expression e.g., = 10*5

cell expression =10*5 while hit enter 50 should be display in cell. Same like do remaining arithmetic operations `


Solution

  • First, let me say that while I think that what you want to do is possible, I also think that it's going to be a ton of work. There are Excel-like components available, and you would likely be better off using one of those.

    That said, you would probably have to implement a cell editors and a cell render and use them for all columns.

    You can customize which keystrokes start editing in cellEditor, and you can also get the keys in the editor, so that you can tell whether editing started with an equal sign or something else.

    Then, once a cell is edited, you'll have to interpret whether it's a literal value or a formula, and store the literal or formula in your data.

    Then, the cellRenderer would have to either display the data directly if it's a literal, or parse and execute the formula, and display the result.