search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

React scheduler PRO (trial) > Best practice for locking in visible dates

Asked by andy
22 hours ago.

I have a custom component above the Daypilot Scheduler that shows current visible start date and visible end date of the Daypilot scheduler for the current zoom level (Quarter as per screenshot).

I am currently getting the visible dates via a native onscroll listener.

  useEffect(() => {
    const el = scheduler?.nav?.scroll;

    if (!el || !myScheduler) return;

    const onScroll = () => {
          const viewport = myScheduler.getViewport();
          const visibleWindowStartDate = viewport.start;
          const visibleWindowEndDate = viewport.end;

          // updateVisibleDates(visibleWindowStartDate, visibleWindowEndDate) 
      });
    };

    el.addEventListener("scroll", onScroll, { passive: true });

    return () => el.removeEventListener("scroll", onScroll);
}, [myScheduler, syncWithLatestViewport]);

Below is relevant Daypilot scheduler props.

zoom={currentZoom}
zoomPosition='middle'
zoomLevel={[{  
  id: ‘quarter’,  
  properties: {    
     "scale": "Week",
    "timeHeaders": [
        {
            "groupBy": "Month",
            "format": "MMM"
        },
        {
            "groupBy": "Week"
        }
    ],
    days: 720,
    "cellWidthSpec": "Fixed",
    "cellWidth": 130,
    "infiniteScrollingEnabled": true,
    "infiniteScrollingMargin": 30,
    "infiniteScrollingStepDays": 365
}}]}


Problem: On smaller screen, because the timeline’s window is smaller, the visible dates can sometimes show `Jan - Feb`, which is only 1 month, instead of 3 months range expected of quarter view. Same issue on very wide screen (ie: showing a visible range as big as 6 months, Jan - Jul).

Question: What is the best practical approach to keep the visible dates consistent, regardless of user’s window size? In the above example, the visible window should always show 3 months range when scrolling, on any screen size.

Considered approaches: I looked into `cellWidthSpec: Auto` which seems to achieve the desired behaviour, but doesn’t work well with infinite scrolling. My first instinct is to find a hacky way to “responsively” calculate `cellWidth`.

Answer posted by Dan Letecky [DayPilot]
21 hours ago.

This is a good approach - take the width of the parent element and calculate the desired cellWidth before Scheduler initialization.

The auto cell width feature uses the same approach. However, it has to be precise and it has to take all other features into account (e.g. row header width auto-fit). That makes it quite expensive in terms of performance.

So if you are happy with an approximate value (or if you are able to calculate it precisely for your scenario) this will work well.

New Reply
This reply is
Attachments:
or drop files here
Your name (optional):