Custom Cell Content

Dynamically customize the cell content of the timeline by showing event-related icons, visual indicators, and a quick add button directly in each cell.

This is achieved using the renderCell function, where event data in each cell is used to display icons based on the event, a badge showing total event hours, and a button to quickly add new events. The add event icon is dynamically added during onCellHoverIn. An event cap per cell is implemented by reading the event count from onCellHoverIn args and enforcing it in onEventCreate, blocking event creation by returning false. This approach helps visualize workload per day and enables quick actions, making scheduling more efficient and user-friendly.

In this demo, cells represent a day. Depending on the resolution, they can also stand for a week, month, or more, while remaining fully customizable. See this configuration demo to try out different timeline resolution settings.

Get started with this example

Demo

Loading the live demo

Preview in full screen

Add workload badges, status icons, and a hover quick-add button to each Timeline cell — and cap events per cell.

Code

import { Eventcalendar, setOptions, Toast  } from '@mobiscroll/react';
import { useCallback, useMemo, useState } from 'react';

setOptions({
  locale:  ,
  theme: ' ',
  themeVariant: ' '
});

function App() {
  const [isToastOpen, setToastOpen] = useState(false);
  const [toastMessage, setToastMessage] = useState();
  const [myEvents, setEvents] = useState(() => [
    {
      id: 1,
      resource: 1,
      title: 'Review',
      start: '2026-11-01T00:00',
      end: '2026-11-01T02:00',
    },
    {
      id: 2,
      resource: 1,
      title: 'Demo',
      start: '2026-11-01T00:00',
      end: '2026-11-01T02:00',
    },
    {
      id: 3,
      resource: 1,
      title: 'Kickoff',
      start: '2026-11-01T00:00',
      end: '2026-11-01T02:00',
    },
    {
      id: 4,
      resource: 4,
      title: 'Strategy',
      start: '2026-11-01T00:00',
      end: '2026-11-01T02:00',
    },
    {
      id: 5,
      resource: 4,
      title: 'Collab',
      start: '2026-11-01T00:00',
      end: '2026-11-01T02:00',
    },
    // Showing partial data. Download full source.
  ]);

  const iconMap = useMemo(
    () => ({
      Review: 'calendar',
      Demo: 'play',
      Kickoff: 'flag',
      Strategy: 'map',
      Collab: 'bubbles',
      Update: 'upload',
      Discussion: 'bubble',
      Planning: 'pencil',
      Retrospect: 'history',
      Onboard: 'user4',
    }),
    [],
  );
  const titles = useMemo(() => Object.keys(iconMap), [iconMap]);

  const myResources = useMemo(
    () => [
      { id: 1, name: 'Resource A' },
      { id: 2, name: 'Resource B' },
      { id: 3, name: 'Resource C' },
      { id: 4, name: 'Resource D' },
    ],
    [],
  );

  const myView = useMemo(
    () => ({
      timeline: {
        endDay: 5,
        eventDisplay: 'fill',
        type: 'month',
        resolutionHorizontal: 'day',
        startDay: 1,
      },
    }),
    [],
  );

  const customDefaultEvent = useCallback(
    (args) => ({
      title: titles[Math.floor(Math.random() * titles.length)],
      end: new Date(args.start.getTime() + 2 * 3600000),
    }),
    [titles],
  );

  const handleAddClick = useCallback(
    (cell) => {
      if (cell.events.length >= 4) {
        setToastOpen(true);
        setToastMessage('Task limit reached');
        return;
      }
      setEvents((prevEvents) => [
        ...prevEvents,
        {
          start: cell.date,
          end: new Date(cell.date.getTime() + 2 * 3600000),
          resource: cell.resource.id,
          title: titles[Math.floor(Math.random() * titles.length)],
        },
      ]);
    },
    [titles],
  );

  const renderCell = useCallback(
    (cell) => {
      const events = cell.events || [];
      const hours = Math.round(events.reduce((s, ev) => s + (new Date(ev.end) - new Date(ev.start)) / 36e5, 0));

      const classMap = { 2: 'light', 4: 'medium', 6: 'semi', 8: 'full' };
      const colorClass = 'mds-timeline-cell-content-badge-' + (classMap[hours] || 'default');

      const addedIcons = new Set();
      const iconHtml = events.map((ev) => {
        const iconName = iconMap[ev.title];
        if (iconName && !addedIcons.has(ev.title)) {
          addedIcons.add(ev.title);
          return <i key={ev.title} className={'mbsc-font-icon mbsc-icon-' + iconName + ' mds-timeline-cell-icon'} title={ev.title}></i>;
        }
        return null;
      });

      return (
        <>
          <div className={'mds-timeline-cell-content-badge ' + colorClass}>{hours}h / 8h</div>
          <button onClick={() => handleAddClick(cell)} className="mds-timeline-cell-content-add">
            +
          </button>
          <div className="mds-timeline-cell-icons">{iconHtml}</div>
        </>
      );
    },
    [handleAddClick, iconMap],
  );

  const renderTimelineEventContent = useCallback((event) => {
    const hours = Math.round((event.endDate - event.startDate) / 36e5);
    return (
      <div>
        {event.title} - {hours}h
      </div>
    );
  }, []);

  return (
    <>
      <Eventcalendar
        cssClass="mds-timeline-cell-content"
        clickToCreate={false}
        data={myEvents}
        dragToCreate={false}
        dragToMove={false}
        dragToResize={false}
        extendDefaultEvent={customDefaultEvent}
        resources={myResources}
        renderCell={renderCell}
        renderTimelineEventContent={renderTimelineEventContent}
        view={myView}
      />
      <Toast isOpen={isToastOpen} message={toastMessage} onClose={() => setToastOpen(false)} />
    </>
  );
}

export default App;

Duplicate Session

You have signed in on a different machine. To keep everything in sync, you have been signed out of this session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.

Duplicate Session

We noticed you are logged in on a different machine and have closed your old session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.