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

Add custom data in attributes #21

Closed
francoislevesque opened this issue Dec 2, 2017 · 3 comments
Closed

Add custom data in attributes #21

francoislevesque opened this issue Dec 2, 2017 · 3 comments
Assignees

Comments

@francoislevesque
Copy link

I need to perform a custom action when an event on the calendar is clicked. It would be far easier to have the event's related data directly in the calendar's attributes array:

attributes: [{
   dot: {
      backgroundColor: '#D52824',
   },
   dates: ['2017-12-25'],
   contentHoverStyle: {
      'cursor': 'pointer',
      'color': '#333'
   },
   // Add this attribute
   customData: {
      'title': 'Christmas Party',
      'url': 'https://events.com/christmas-2017'
   }
}]
@nathanreyes
Copy link
Owner

It's funny you mention this as I'm currently implementing this feature. I was calling it tag rather than customData as you referenced. I do kind of like customData though, although the exact name doesn't matter as much as long as it is clear what the intention is.

@nathanreyes nathanreyes self-assigned this Dec 2, 2017
@francoislevesque
Copy link
Author

Yeah perfect! :)

@nathanreyes
Copy link
Owner

In 0.4.0, when day events are triggered (daySelect, dayMouseEnter, dayMouseLeave), you can access the attributes like before, but with a few differences.

  • Instead of the attributes being attached to the day info parameter, they are passed in via the 2nd parameter
  • The attributes are reduced to an object using the attribute keys.

So your example might look something like this:

data() {
  attributes: [{
    key: 'party', // Use your own key here, or if not a random number will be assigned
    dot: {
      backgroundColor: '#D52824',
    },
    dates: ['2017-12-25'],
    contentHoverStyle: {
      'cursor': 'pointer',
      'color': '#333'
    },
    // Add this attribute
    customData: {
      'title': 'Christmas Party',
      'url': 'https://events.com/christmas-2017'
    }
  }]
},
methods: {
  daySelect(dayInfo, attr) {
    // Get the custom data
    const customData = attr.party.customData; // Uses the key from above
  }
},
...

Let me know if you experience any issues. The documentation still needs to be updated to reflect these changes.

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