Catch updates on cells unified, no matter if is direct input or formula

Tags: #<Tag:0x00007f0aff4d4598> #<Tag:0x00007f0aff4d4458>

Hi!

I have a datagrid with multiple formulas referring multiple cells, I need to generate SQL query for every updated cell, no matter how it’s been updated:

  • manual input or copy/paste
  • formulas calculated results

Up until now I tried to use hooks:

  • afterChange: gives me the cells updated manually
  • afterFormulasValuesUpdate: gives me all cells on the initial load and the calculated formulas after first init

But I’d like to get all cells update with “afterChange” including formula calculated results

Or maybe from the hotInstance there is a plugin/method to get all updated values??

Thanks beforehand

Kindly
Jose

Hi @joseic

With cell dependencies based on formulas the afterFormulasValuesUpdate is the right choice (afterChange does not work for formula dependencies). Now, if you wouldn’t want to run it on the initialization you can use the addHook method after initializing the instance, like so


hot.addHook('afterFormulasValuesUpdate', function(){
  	console.log(arguments)
})

Example: https://jsfiddle.net/handsoncode/4e50u1x2/

Would that work for you?

Hi @aleksandra_budnik,

Thank you very much for your quick response!

I’ll try that approach.

However I wonder if the hot instance is keeping state of data so we can read at any time current values of every cell?

Thank you very much

Kindly
Jose

However I wonder if the hot instance is keeping state of data so we can read at any time current values of every cell?

Yes, you can read the value via getDataAtCell() and/or getSourceDataAtCell() method. In our case from the demo https://jsfiddle.net/handsoncode/ndem3gbu/ the ~data will return a value of the formula for cell 3, 3 and the ~sourceData will return the formula. Example https://jsfiddle.net/handsoncode/ndem3gbu/

The only exception of keeping the state is when you perform batch operations (ref: docs) - as there you can proceed with many operations one after another and the hooks will get the info after the batch is closed.

All right!

I think I’ll be able to handle it from here

Very insightful, thank you very much

Always happy to help. I keep my fingers crossed for progress.