1

I am trying to set a vuejs variable from within handsontable.

The vuejs variable:

this.dataChanged

in code block below is not available from handsontable settings, any idea how can I access it?

<template>
<div id="hot-container">
<HotTable :root="root" :settings="hotSettings"></HotTable>
</div>
</template>

<script>
export default {

data() {

return {
  #vuejs variable i want to set from hot
  dataChanged: false,
  root: 'test-hot',
  hotSettings: {
    data: [{something: 0}],
    afterChange: function(changes, src) {
      if (src !== 'loadData') {
        this.dataChanged = true
      }
},
methods: {
  saveChanges: function () {
    if (this.dataChanged){
      //save data
    }
  }
}
1
  • Do you have any code which uses handsontable with the code above? Commented Jan 5, 2018 at 14:38

3 Answers 3

3

I faced this same problem... I found a workaround posted on GitHub like so..

This way you can access all Vue's data, methods, etc as you normally would.

data() {
   return {
     hotSettings: {
       ...
       afterChange: this.afterChangeVue
       ...
     }
   }
},
methods: {
    afterChangeVue(changes, source) {
      console.log('changes, source => ', changes, source);
      console.log('this.$store => ', this.$store);
    },

Here is the link to the original thread: https://github.com/handsontable/vue-handsontable-official/issues/7#issuecomment-356190395

Sign up to request clarification or add additional context in comments.

Comments

0

I ended up saving to a variable declared outside of vue - ie above the data () declaration

var myNewVar = 42
data() {
    #can save to myNewVar from here

Comments

0

Just like @Rosdi_Kasim said, but much simpler with fat arrow function

data() {
   return {
     hotSettings: {
       /*...*/
       afterChange: (changes, source) => {
         console.log('changes, source => ', changes, source);
         console.log('this.$store => ', this.$store);
       }
       /*...*/
     }
   }
},
methods: {
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.