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

Accessing resource in custom header #1870

Open
developerkam opened this issue Feb 25, 2021 · 2 comments
Open

Accessing resource in custom header #1870

developerkam opened this issue Feb 25, 2021 · 2 comments

Comments

@developerkam
Copy link

Do you want to request a feature or report a bug?

feature

What's the current behavior?

I want to add some functionality (button or inputs) to day header. When button clicked, I need to pass date and resourceId to my function. Date is already passed to custom header but I cannot access resourceId.

What's the expected behavior?

components={{
  day: {
     header: ({date, label, localizer /* resource may be added here */}) =>
          <div>
              <div>{moment(date).format("DD/MM/YYYY")}</div>
              <button onClick={() => this.doSomething(date, resourceId)}></button>
          </div>
  }
}}
@juan-giovanolli
Copy link

Have you found any solution to that?

@developerkam
Copy link
Author

Sorry for late reply...

As workaround, I had put resource id to element, then queried the element from dom.

resourceTitleAccessor={(resource) => <div className="custom-resource-header" id={resource.id}>...</div>}

day: { header: ({date, localizer}) => (<CustomInput />) }

class CustomInput extends Component {

componentDidMount() {
    this.resourceId = this.myDiv ?
                            Number(this.myDiv
                                .closest('.rbc-time-header-content')
                                .querySelector('.custom-resource-header')
                                .id)
                            : undefined;
}

render() {
     return (<div ref={ref => this.myDiv = ref}>...</div>);
}

}

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

3 participants