Schedule - Make month columns narrower

Is it possible to make the date columns narrower in Month view? As shown in the screenshot below, I am able to see September 1 - 17 with the default width. I would like to reduce the column width of each day by a little bit so that my users can see more days while in month view without scrolling.



Is it possible to control the date column width?


4 Replies

VD Vinitha Devi Murugan Syncfusion Team September 8, 2022 09:27 AM UTC

Hi Justine,


Greetings from Syncfusion Support


We have validated your reported query and suspect that you want to remove the horizontal scroller while rendering scheduler and achieved it by using eventRendered and actionComplete event of our schedule with following CSS. We have prepared the below sample for your reference with your code snippet which you shared in one of your previous incident.


https://stackblitz.com/edit/react-timelinemonth-without-horizontal-scroll


.e-schedule
.e-timeline-month-view
.e-date-header-wrap
table
col,

.e-schedule
.e-timeline-month-view
.e-content-wrap
table
col {

  widthauto
!important;

}


  onActionComplete(args) {

    if (

      args.requestType === 'viewNavigate' ||

      args.requestType === 'dateNavigate'

    ) {

      this.dayWidth = null;

    }

  }

  onEventRendered(args) {

    if (this.currentView === 'TimelineMonth') {

      this.dayWidth =

        this.dayWidth ??

        document.querySelector('.e-date-header-wrap').clientWidth /

          (new
Date(

            this.selectedDate.getFullYear(),

            this.selectedDate.getMonth() + 1,

            0

          ).getDate() *

            this.scheduleObj.activeViewOptions.interval); //To calculate the width of a work cell

      const
diffInDay = args.data.data.count//To calculate the number of days an event rendered.

      const
td = document.querySelector(

        '.e-work-cells[data-date="' +

          this.resetTime(args.data.StartTime).getTime() +

          '"]'

      ); //To find the work cell element in which the appointment started

      const
left = td ? td.offsetLeft : args.element.style.left//To calculate the left position of that work cell

      args.element.style.left = left + 'px'//To assign the above left position to the appointment element

      args.element.style.width = diffInDay * this.dayWidth + 'px'//To set width for the appointment element.

    }

  }


Kindly try with the above sample and get back to us if you need any further assistance.


Regards,

Vinitha



JS Justin Schnurer September 8, 2022 12:52 PM UTC

How can I accomplish this in a React functional component? Also, I do not want the cells to be auto width. Instead, I want to be able to set them to EXACTLY 25px or 70px or whatever measurement I want to use.



JS Justin Schnurer September 8, 2022 02:20 PM UTC

This doesn't seem to work for me.


I have set the following styles, attempting to set the columns to 40px wide:

/deep/ .timeline-resource-grouping.e-schedule:not(.e-device)
  .e-agenda-view
  .e-content-wrap
  table
  td:first-child {
  width: 90px;
}

/deep/ .timeline-resource-grouping.e-schedule .e-agenda-view .e-resource-column {
  width: 100px;
}

/deep/ .e-schedule .e-timeline-month-view .e-date-header-wrap table col,
/deep/ .e-schedule .e-timeline-month-view .e-content-wrap table col {
  /** Style to control the width of month columns manually */
  width: 40px !important;
}


I've added this ref to my functional component code:

const dayWidth = useRef<number | undefined>(undefined);


I also have a variable for the schedule component by using this:

  const [schedulerRef, setSchedulerRef] = useState<ScheduleComponent | undefined>(undefined);


const onRefChange = useCallback((scheduler: ScheduleComponent | null) => {
    setSchedulerRef(scheduler ? scheduler : undefined);
  }, [setSchedulerRef]);


<ScheduleComponent
          ref={onRefChange}


In the eventRendered event, I have added this code.

if (schedulerRef?.currentView === 'TimelineMonth') {
  dayWidth.current =
    dayWidth.current ??
    (document.querySelector('.e-date-header-wrap')?.clientWidth || 0) /
    (new Date(
      schedulerRef.selectedDate.getFullYear(),
      schedulerRef.selectedDate.getMonth() + 1,
      0
    ).getDate()
      * (schedulerRef.activeViewOptions.interval as number)); //To calculate the width of a work cell

  const diffInDay = args.data.data.count; //To calculate the number of days an event rendered.

  const cellSelector = '.e-work-cells[data-date="' +
    resetTime(args.data.startTime).getTime().toString() +
    '"]';

  const td = document.querySelector(cellSelector); //To find the work cell element in which the appointment started

  const left = td ? (td as any).offsetLeft : args.element.style.left; //To calculate the left position of that work cell

  args.element.style.left = left + 'px'; //To assign the above left position to the appointment element
  args.element.style.width = diffInDay * dayWidth.current + 'px'; //To set width for the appointment element.
}

Since I am using Typescript, many of the provided lines of code were reported as unsafe due to the fact various things could be undefined. Also, React reports that the "td" has no offsetLeft property. I had to make minor adjustments to the way it was written.


Finally, I also added the actionComplete event:

          actionComplete={(args) => {
            if (
              args.requestType === 'viewNavigate' ||
              args.requestType === 'dateNavigate'
            ) {
              dayWidth.current = undefined;
            }
          }}


The issue now is that when the window is resized or the layout changes, the events are the incorrect width.

 Notice in this first screenshot that the layout is correct for this event. It starts on the 3rd and ends on the 9th.



However, when I expand my main menu on the left side of the website, it shifts the scheduler over and causes the event to be the incorrect width. Notice that it no longer starts EXACTLY on the 3rd and now ends near the end of the 10th.




VD Vinitha Devi Murugan Syncfusion Team September 9, 2022 10:08 AM UTC

Hi Justin,


Greetings from Syncfusion Support.

We suggest you to call refreshEvents or refreshLayout method inside main menu layout resize event to resolve issue. 


Refresh (method): https://ej2.syncfusion.com/react/documentation/api/schedule/#refreshlayout

                                  https://ej2.syncfusion.com/react/documentation/api/schedule/#refreshevents


Kindly refer the above solution and get back to us for further assistance.


Regards,

Vinitha


Loader.
Up arrow icon