handsontable / ngHandsontable

Official AngularJS directive for Handsontable
http://handsontable.github.io/ngHandsontable/
MIT License
433 stars 159 forks source link

How to get the HOT instance? #226

Closed Maximaximum closed 6 years ago

Maximaximum commented 6 years ago

I'm using the HOT directive like this:

      <hot-column data="Email" title="'E-mail'" validator="$ctrl.RequiredValidator"></hot-column>
      <hot-column data="LastName" title="'Family Name'" validator="$ctrl.RequiredValidator"></hot-column>
      <hot-column data="FirstName" title="'First Name'" validator="$ctrl.RequiredValidator"></hot-column>
      <hot-column data="Gender" title="'Male/Female'" type="'dropdown'" source="$ctrl.genderOptions"></hot-column>
      <hot-column data="JobTitle" title="'Job Title'"></hot-column>
      <hot-column data="Telephone" title="'Telephone'"></hot-column>
    </hot-table>

Now, in my controller I need to call hotInstance.validateCells() at a certain place in code. But how do I get the hotInstance?

I couldn't find any info on this in the docs.

AMBudnik commented 6 years ago

Hi @Maximaximum

I have a demo that may help http://jsbin.com/digupecame/edit?html,js,output

Maximaximum commented 6 years ago

Thanks a lot! Yet another question. I'd love to store the hotInstance as a property on my controller class, rather than calling hotRegisterer.getInstance() each time I need to get the instance. But if I try to get the instance in the controller constructor, or in the $onInit method (it's an angularjs component, not a general directive), getInstance() returns undefined (obviously, it hasn't been constructed yet). Could you give me a hint on which controller lifecycle hook should I use to be able to reliably get the instance?

AMBudnik commented 6 years ago

Sorry for the delay. I have checked some possible approaches and ask our developer but currently this action i not available