handsontable / hyperformula

HyperFormula is an open-source headless spreadsheet for business web apps. It comes with over 400 formulas, CRUD operations, undo-redo, clipboard support, and sorting.
https://hyperformula.handsontable.com/
GNU General Public License v3.0
1.88k stars 107 forks source link

[Bug]: No change event is emitted when the formula changes #1408

Open nomind2think opened 2 months ago

nomind2think commented 2 months ago

Description

when i insert/remove row, formula's relative address is change, but no valueUpdateEvent emit, how to listening this event?

    const engine = HyperFormula.buildFromArray([
      ['1', '=SUM(A1:A2)'],
      ['1'],
    ])
    engine.on('valuesUpdated', (changes)=>{console.log(changes)})
    engine.addRows(engine, 0, [1, 1])
    //==SUM(A1:A3)
    console.log(engine.getCellFormula(adr('B1')))

Video or screenshots

No response

Demo

none

HyperFormula version

2.7.0

Your framework

vue

Your environment

nodejs v18.17.1

adrianszymanski89 commented 2 months ago

Hi @CodeChaosConjurer

Thank you for contacting us. I tried to recreate this behavior in this example, but there seems to be something wrong: https://stackblitz.com/edit/vitejs-vite-pjjrzz?file=index.html,main.js&terminal=dev. Can you please modify it so it matches your scenario?

nomind2think commented 2 months ago

Hi @CodeChaosConjurer

Thank you for contacting us. I tried to recreate this behavior in this example, but there seems to be something wrong: https://stackblitz.com/edit/vitejs-vite-pjjrzz?file=index.html,main.js&terminal=dev. Can you please modify it so it matches your scenario?

https://stackblitz.com/edit/stackblitz-starters-2wmbyf?file=index.js i'm create a new stack. without vite, just simple with nodejs. I want to listener formulas change event.

adrianszymanski89 commented 2 months ago

Hi @CodeChaosConjurer

Unfortunately, this example still doesn't work for me. However, if you need a listener, did you try this method? https://hyperformula.handsontable.com/api/interfaces/listeners.html#values

nomind2think commented 2 months ago

Hi @CodeChaosConjurer

Unfortunately, this example still doesn't work for me. However, if you need a listener, did you try this method? https://hyperformula.handsontable.com/api/interfaces/listeners.html#values

Hi, i'm fork your stackblitz, https://stackblitz.com/edit/vitejs-vite-yhajtz?file=index.html,main.js&terminal=dev will it work? i try to use listening valuesUpdated event,but no event emit.B1's raw formulas is =SUM(A1:A2),after insert row is =SUM(A1:A3), The value is not updated but the formula is. But no event emit. I try to explain the steps to reproduce. The first step is to create a sheet with a formula as a relative reference address. The second step is to insert or delete a row that affects the expression of the formula but does not affect its value. This way there will be no valueUpdate event.

For example, the formula in cell B1 is =SUM(A1:A2). If you insert a row after the first row, the formula in B1 becomes =SUM(A1:A3), but the value of the inserted row is 0, which will not happen. Modify the value of B1, but the formula of B1 has changed and I cannot receive any events.

adrianszymanski89 commented 2 months ago

Hi @CodeChaosConjurer

I'm not sure if this example was updated. It throws an error that adr is not defined. Can you please check it again?

nomind2think commented 2 months ago

Hi @CodeChaosConjurer

I'm not sure if this example was updated. It throws an error that adr is not defined. Can you please check it again?

sorry,try it again, i don't know how to run this program

nomind2think commented 2 months ago

Hi @CodeChaosConjurer

I'm not sure if this example was updated. It throws an error that adr is not defined. Can you please check it again?

i 'm already fix it, plz try it again

adrianszymanski89 commented 2 months ago

Hi @CodeChaosConjurer

Thank you. Now it works. We'll take a closer look at this, and I'll get back to you when I have more information.

nomind2think commented 2 months ago

Hi @CodeChaosConjurer

Thank you. Now it works. We'll take a closer look at this, and I'll get back to you when I have more information.

Thank you~

adrianszymanski89 commented 2 months ago

Hi @CodeChaosConjurer

We determined that, according to the documentation, this behavior is correct: https://hyperformula.handsontable.com/api/interfaces/listeners.html#valuesupdated

This hook is only fired on value change, not the formula, so it's the correct behavior in your case.

Here's an updated example showing that it works as expected: https://stackblitz.com/edit/vitejs-vite-ex3waj?file=index.html,main.js&terminal=dev

nomind2think commented 2 months ago

Hi @CodeChaosConjurer

We determined that, according to the documentation, this behavior is correct: https://hyperformula.handsontable.com/api/interfaces/listeners.html#valuesupdated

This hook is only fired on value change, not the formula, so it's the correct behavior in your case.

Here's an updated example showing that it works as expected: https://stackblitz.com/edit/vitejs-vite-ex3waj?file=index.html,main.js&terminal=dev

ok,thanks,Is there any way for me to listen for formula change events?

adrianszymanski89 commented 2 months ago

Hi @nomind2think

Currently, there's no such method available, but this is valuable feedback and that might be a good idea to add such method in the future.

nomind2think commented 2 months ago

Hi @nomind2think

Currently, there's no such method available, but this is valuable feedback and that might be a good idea to add such method in the future.

ok,thanks,I think this can be closed, what do you think?

AMBudnik commented 2 months ago

Hi @nomind2think we can keep it open as a feature. I've just attached the exact label this this issue.