Hi there,
I need to retrieve the cell data on an event click in order to correctly position my custom quick info popup. Currently, the cellClick method provides the relevant element that I need (
). How do I get the cell td on an event click? Currently, the element that is retrieved is the div that holds the quick popup. Some additional information that may be helpful: I need the anchor element that is part of the document layout in order to render a Material UI Popper.
[index.js]
const onEventClick = (args) => { let start = args.event.StartTime.getTime(); let end = args.event.EndTime.getTime(); let time = (scheduleObj.current.timeScale.interval / scheduleObj.current.timeScale.slotCount) * 1000 * 60; for (let i = start; i < end; i = i + time) { var cellDetails = scheduleObj.current.element.querySelector( '.e-work-cells[data-date="' + i + '"]' ); console.log(cellDetails); } }; |
There is not a more straightforward answer? I need to access the dom node that represents the time of the appointment. Seems like there should be a simple way to access this information instead of manipulating cell data.
Additionally, with this response I am still getting the error that "The anchor element should be part of the document layout. Make sure the element is present in the document or that it's not display none." This is the element I get when selecting an event: <td aria-selected="false" class="e-work-cells e-alternate-cells e-work-hours" data-date="1687365000000" data-group-index="0"></td>.
Can you please provide a better solution? This is inhibiting the production of my application. Thank you.
Hi Jessica,
Q1: I need to access the dom node that represents
the time of the appointment
In cellClick and eventClick events of the Schedule we provided
respective target elements and its related details. If you want the cell
details in the eventClick event of the Schedule, we suggest you achieve
that requirement using our previous solution at your application end like
highlighted in the below code snippet. Since you want that cell detail to
position your custom quick info popup. In the eventClick event of the
Schedule you will get the clicked appointment element. So, we suggest you use
the appointment element to position your custom quick info popup.
Sample: https://stackblitz.com/edit/react-schedule-get-cell-details-event-pygs3m?file=index.js
[index.js]
|
const onEventClick = (args) => { // Use the appointment element present in the args element or use the cell queried in the targetCell variable console.log(args.element); var targetCell = scheduleObj.current.element.querySelector('.e-work-cells[data-date="' + args.event.StartTime.getTime() + '"]'); console.log(targetCell); }; |
Q2: I am still getting the error that "The anchor element should be part of the document layout. Make sure the element is present in the document or that it's not display none."
We are unable to reproduce the issue at our end. We suspect that the issue is not related to the Schedule. We suggest you check the other customization that you have done in your project. If you still facing problem, share more details about the issue.
Regards,
Venkatesh
Thank you! This ended up working as I expect it to.
As a follow up, I have implemented the schedule component in another application where I have multiple resources. When I click on a cell to retrieve the appropriate <td></td> element in my popupOpen function via args.target, I am getting a similar warning that says "Node cannot be found in the current page" when I click on the element in the console. Do you have a similar solution? Thank you!
Are you able to provide a resolution to this problem?
Hi Jessica,
Query: I am getting a similar warning that says "Node cannot be found in the current page" when I click on the element in the console
We checked your shared codes at our end in your shared code you are setting up args.cancel = true and using the args.element in the setAnchorEl method. The element in the args.element is the Schedule quick info popup. Since you are setting up args.cancel = true the popup element will be hidden in the DOM. We suspect that because of that you are facing your reported problem. We suggest you use the args.target(Contains clicked target cell element) instead of args.element in the setAnchorEl method. If you still facing the same problem, share the below details to proceed further.
Regards,
Ravikumar Venkatesan
Hi there,
Here are additional code snippets to portray my issue. I need to pass in an anchor el to my QuickInfoPopup component, which renders a custom material UI popper component. When setting the anchorEl in the onPopupOpen function, I get an error in my console saying "The `anchorEl` prop provided to the component is invalid. The anchor element should be part of the document layout. Make sure the element is present in the document or that it's not display none." I used the solution provided above in a different scheduler component I rendered that did not have multiple resources and it worked perfectly, so I am wondering if that is one of the problems I am facing. If you are able to respond today, I would greatly appreciate it. Thank you. Let me know if you need additional information.
Hi Jessica,
We checked your
requirement based on your shared details at our end and we suggest you pass the
popupOpen event args.target(Contains clicked cell or appointment
element) element in setAnchorEl, this will open popper component in
respective target cell or appointment. Kindly check the below sample and let us
know if you need further assistance.
Sample: https://stackblitz.com/edit/react-fcu7ov?file=demo.tsx,index.html
[demo.tsx]
|
function onPopupOpen(args) { if (args.type === 'QuickInfo') { args.cancel = true; setPopupOpen(true); setAnchorEl(args.target); } } |
Regards,
Mugilraj G
Hi there,
I figured the issue out. For some reason, I was unable to grab a valid DOM node from the popupOpen method, but I was able to via the cellClick and eventClick methods. Do you know why this might be? I have implemented this fix but would like to understand why this was happening.
Additionally, I realized that when I navigate to my month view, cellDetails is set to null which means that the correct cell cannot be found. I believe it has to do with the date. Are you able to assist? This is my code for the eventClick method.
[demo.tsx]:
function onCellClick(args) { args.cancel = true; setPopupOpen(true); setAnchorEl(args.event.target); } function onEventClick(args) { args.cancel = true; setPopupOpen(true); setAnchorEl(args.originalEvent.target); } |
I am using this function for three different views: timeline day, timeline week, and timeline month. The eventClick function is working for my timeline day and timeline week views, but my issues lies within the timeline month view. As mentioned above, I need to retrieve the td component on event click. This is why I am not simply setting my anchor element to the div, but rather I am implementing the logic in the function to retrieve the td cell. Can you please offer a solution that uses the logic in this function and also works for the timeline month view?
Jessica,
Sample: ej2-react-schedule-with-popper-customization - StackBlitz
You can set the target for the Popper component on the event click in the TimelineMonth view by making the below-highlighted changes in the handleEventClick method.
[demo.tsx]
|
import { ScheduleComponent, ViewsDirective, ViewDirective, ResourcesDirective, ResourceDirective, TimelineViews, TimelineMonth, Inject, resetTime } from '@syncfusion/ej2-react-schedule';
export default function SimplePopper() {
function handleEventClick(args) { let resourceIndex = clients.findIndex(c => c.id === args.event.ClientId); let start = (scheduleObjRef.current.currentView === 'TimelineMonth' ? resetTime(args.event.startTime) : args.event.startTime).getTime(); let end = (scheduleObjRef.current.currentView === 'TimelineMonth' ? resetTime(args.event.endTime) : args.event.endTime).getTime(); let time = scheduleObjRef.current.currentView === 'TimelineMonth' ? 86400000 : (scheduleObjRef.current.timeScale.interval / scheduleObjRef.current.timeScale.slotCount) * 1000 * 60; for (let i = start; i <= end; i += time) { let cellDetails = scheduleObjRef.current.element.querySelector('.e-work-cells[data-date="' + i + '"][data-group-index="' + resourceIndex + '"]'); setAnchorEl(cellDetails); } } } |
This is tremendously helpful, thank you!
Jessica,
You're welcome! Thanks for your feedback.
Hi there - I have had to adjust my code and am encountering the same issue whereby I can retrieve a td element, but when I set it as an anchor element my console is telling me that "Node cannot be found in the current page." This is the node I am grabbing:
<td aria-selected="false" colspan="1" class="e-work-cells e-alternate-cells e-work-hours" data-date="1704225600000" data-group-index="0"></td>. Additionally, if I have more than one appointment in this view (e.g. multiple clients and each client has multiple appointments) the behavior is not working correctly. Can you please prepare a demo for me to take a look at that works? I have a deadline for this feature, so I would really appreciate it this request could be expedited.
Also, the customPopper component is using the material UI popper component
Thank you!
Hi Jessica Newman,
We have attempted to reproduce your reported issue based on the code snippet you have provided, but unfortunately, we were unable to replicate the problem on our end. To assist you more effectively, we would appreciate if you could provide additional details. Specifically, it would be helpful if you could reproduce the issue in the sample we shared or provide a sample that reproduces the issue.
By doing so, we can better understand the context and conditions under which the issue occurs, which will enable us to provide a more accurate and effective solution. Thank you for your cooperation.
Regards,
Ram