YakovL YakovL -3 years ago 118
Javascript Question

Handsontable: how to get instance by container?

I need to create a function that does some data updates and re-rendering to a rendered instance of handsontalbe (

var ht = new Handsontable(el,options)
). What I can easily get in my case is
el
(the element which is used as a container of the instance). Is it possible to get
ht
by only knowing
el
? Or I have to "remember"
ht
somewhere to access it later?

(I've tried
Handsontable(el)
and it creates a new table, it doesn't return an already created instance)

Answer Source

You can't get the handsontable object from the DOM Element from which it has been constructed. The handsontable instance is just a wrapper, which controls DOM Element for viewing, and that element does not have reference to its wrapper.

That means you indeed need to store your reference to ht somewhere, just like you would another variable.

If your problem is the scope, make the table a property of window object, and it will be accessible from everywhere in your page. This can be done simply using:

window.ht = new Handsontable(el,options)

However, if possible avoid making such global variables and keep it in the proper scope.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download