Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template function #52

Closed
HenoTaMyJIb opened this issue May 31, 2016 · 5 comments
Closed

Template function #52

HenoTaMyJIb opened this issue May 31, 2016 · 5 comments

Comments

@HenoTaMyJIb
Copy link

Hi, thank you for vue-tables.

There is another question.

On "VueTables Options API" page, there is an example

templates: {
  edit:"<a href={id}><i class='fa fa-edit'></i></a>",
  age:function(row) {
       return this.calcAge(row.birth_date);
  } 
}

In this case this doesn't refer to a Vue instance?
Where method calcAge should be defined? Or am I doing something wrong?
https://jsfiddle.net/w7u7tf7p/

@matfish2
Copy link
Owner

matfish2 commented May 31, 2016

It is merely an example, not copied from the demo fiddle.
Of course, if you want this to work you need to implement a calcAge method on the vue instance.

@HenoTaMyJIb
Copy link
Author

Wrong link.
https://jsfiddle.net/w7u7tf7p/2/

Implement like this?

methods: {
    deleteMe: function(id) {
      alert("Delete " + id);
    },
    calcAge: function(date) {
            var age = 0;
            // calculations
            return age;
        }
  },

Getting is not a function error

@matfish2
Copy link
Owner

matfish2 commented May 31, 2016

It appears that this inside the function refers to the window object.
I suppose you can use a global function or simply write the logic in the template function.
I will remove this from the example.

@HenoTaMyJIb
Copy link
Author

Thank you for help!

@matfish2
Copy link
Owner

matfish2 commented Oct 10, 2016

I have added (7bdaa05) the root vue instance (this.$root from the component's perspective) as the this context for the function. Now you CAN use this.calcAge inside the function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants