Get cell value

Tags: #<Tag:0x00007efc64f1c1a8>

Continuing the discussion from Code example for "Get cell value":

Hi Aleksandra,

I come back to your answer again:

The example you give here returns the value “undefined” when I click on the button:

https://jsfiddle.net/d14npbom/3/

But it should return a specific cell value as I understood.

Is the function not correct working?

Thanks for your help!

In that example the mechanism checks only the 0, 0 cell

if (row == 0 && col == 0) {
        myVariable = changes[0][3]
}

If you’d like to get the value of any cell, just remove the condition https://jsfiddle.net/baswguoz/1/

And of course on the initial load it is undefined as (as I remember) it needed to show only the changes, and when where are no changes the value is undefined. Is that correct or did I miss anything?

Almost.

What would the code have to be so that the value of the cell marked in red:

  1. is displayed automatically at the beginning (without having to press the button)
  2. is displayed automatically after each change (without having to press the button)

?

I would like to be able to insert the marked cell value via myVariable at any time at any point of the web site via javascript.

Is that possible ?

image

Well, so just move the logic from the button to the afterChange() hook, like here https://jsfiddle.net/xv7zy0js/ If you want to show undefined when the table loads you can leave it like in the demo. And if you prefer to skip undefined and show only value when it changes when you should move the innerHTML part into the if(changes) condition.

Thank you for your answer, Aleksandra.

Unfortunately, I don’t quite understand it yet and it’s not the solution I’m looking for.

I would like only the value of the red marked cell to be “printed”:

  1. from the beginning, as soon as the table is shown for the first time.
  2. respectively when the value is changed

Or in other words: myVariable should output the current value of the cell marked in red at any time.

In your example https://jsfiddle.net/xv7zy0js/ it is still the case that when the table is loaded for the first time, undefined is shown first, not the value 7000.

Or have I misunderstood something?

Please check this demo https://jsfiddle.net/fu204zoL/2/, @tomnovo

Hello Aleksandra,

Yes, that’s in essentially what I was looking for! :star_struck: Thank you very much! I can already work well with that.

But two questions remain for me:

1.) The value 7000 is placed in the HTML element print. When I want to output myVariable via document.write, nothing is displayed. I ask because the innerHTML version unfortunately does not work to pass to the value to Bubble.io. I’ve recreated what I mean here:

https://jsfiddle.net/ovkaz67b/

2.) If I want to output multiple cells (for example 50 cells) from a very large table via JS variables, what is the smartest way to do it without making the code bulky?

You have already helped me a lot up to this point. I appreciate your help very much.

Tom

Ad 1) There’s an error in the console. It might be just a JSFiddle issue (the way they treat script order).

25

Ad 2) Are those 50 cells follow any pattern? For example, do they have the same key in the object dataset or are all of the cells in the table? Also, how do they should display (loaded to another table, one after another, etc.)

Ad 1) I tested exactely the code https://jsfiddle.net/ovkaz67b/ in Bubble. But it did show only the div-Epxression, not the document.write output beneath. Is there another way to pass only the myVariable value?

Ad 2) All the cells are in a single large table with about 4,000 cells or more if I remember correctly. There are some cells that are in a row. But very many other cells that have to be read at very different positions in the table.

@tomnovo it seems that this issue has nothing to do with Handsontable. Is the matter of using the same variable between the scripts. I think that this is more a question to Bubble how do they allow you to pass those variables.