react-big-schedule icon indicating copy to clipboard operation
react-big-schedule copied to clipboard

Scheduler width adjustment

Open moreswapnil95 opened this issue 11 months ago • 5 comments

Checklist

  • [X] I've looked through the README
  • [X] I've verified that I am running react-big-schedule latest version.
  • [ ] I've searched the existing issues and discussions for a similar question
  • [ ] I've provided relevant code snippets or error messages
  • [ ] I've included steps to reproduce the issue
  • [ ] I've checked the browser console for any errors
  • [ ] I've tested the issue with the latest version of react-big-schedule

Please make sure the question is worded well enough to be understood

how to adjust scheduler width as per outer div width

moreswapnil95 avatar Mar 19 '24 04:03 moreswapnil95

image

moreswapnil95 avatar Mar 20 '24 08:03 moreswapnil95

Hello @moreswapnil95 this is currently not possible directly but by taking out parent div width by using use ref or something and passing that width to the scheduler config you can do that.

ansulagrawal avatar Mar 20 '24 18:03 ansulagrawal

got this one when drag & drop @ansulagrawal image

whoafridi avatar Aug 28 '24 06:08 whoafridi

@whoafridi don't add your issue here create a new issue for this

ansulagrawal avatar Aug 28 '24 11:08 ansulagrawal

I'm kinda proud of this hack.

so added a couple of useRefs

const contentContainerRef = useRef<HTMLDivElement>(null); const scheduleContainerRef = useRef<HTMLDivElement>(null);

A useEffect to traverse into the component.

useEffect(() => {
    // hack into the react-big-schedule component and override styles for responsiveness
    const updateWidths = () => {
      if (scheduleContainerRef.current && contentContainerRef.current) {
        const contentWidth = contentContainerRef.current.offsetWidth;

        const schedulerTable = scheduleContainerRef.current.querySelector(
          '.scheduler',
        ) as HTMLElement;
        if (schedulerTable) {
          schedulerTable.style.width = '100%';
        }

        const resourceView = scheduleContainerRef.current.querySelector(
          '.resource-view',
        ) as HTMLElement;
        const resourceViewWidth = resourceView
          ? resourceView.offsetWidth
          : 160;

        const schedulerView = scheduleContainerRef.current.querySelector(
          '.scheduler-view',
        ) as HTMLElement;
        if (schedulerView) {
          schedulerView.style.width = `${
            contentWidth - resourceViewWidth - CONTENT_PADDING * 2
          }px`;
        }
      }
    };

    updateWidths();
    window.addEventListener('resize', updateWidths);

    return () => {
      window.removeEventListener('resize', updateWidths);
    };
  }, []);

And then some wrapping...

return (
    <DndProvider backend={HTML5Backend}>
      <div
        ref={contentContainerRef}
        className="pt-6 w-full"
        style={{
          paddingLeft: `${CONTENT_PADDING}px`,
          paddingRight: `${CONTENT_PADDING}px`,
        }}>
            <div ref={scheduleContainerRef}>
                <Scheduler
                  schedulerData={viewModel}
                  ...
                />
             </div>
        </div>
    </DndProvider>)

devpascoe avatar Sep 02 '24 03:09 devpascoe