Custom Header

You can customize how the header of the agenda looks and how the components are arranged. Besides that you can also add custom functionality, like a segmented control that lets people switch between agenda and calendar.

Use the renderHeader option for passing a custom header layout. There are predefined components - shorthands if you will - that can be used to assemble the header:

  • Navigation component - <CalendarNav />. Use the .md-header-filter-controls CSS class for custom overrides.
  • Today button - <CalendarToday />. Use the .md-header-filter-today CSS class for custom overrides.
  • Previous month button - <CalendarPrev />. Use the .md-header-filter-prev CSS class for custom overrides.
  • Next month button - <CalendarNext />. Use the .md-header-filter-next CSS class for custom overrides.

For changing the order the controls are laid out, you only need to set up the renderHeader. This example sets a consistent order and layout across all themes and shows a custom control at the far right end.

Overriding the order for specific themes

For a custom order on a theme to theme basis, you will need to use a little CSS. Flex layout makes reordering easy. It's just a matter of setting the order in CSS. For material use the .mbsc-material, for windows the .mbsc-windows prefix and for iOS it is .mbsc-ios class. Eg.:

.mbsc-material .md-header-filter-prev { order: 1; }
            .mbsc-material .md-header-filter-next { order: 2; }
            .mbsc-material .md-header-filter-controls { order: 3; }
            .mbsc-material .md-header-filter-today { order: 4; }
Want to add a filter to the header?  Check out the next example →
Get started with this example

Demo

Loading the live demo

Preview in full screen

Build a custom header for the event calendar agenda — assemble navigation controls, add a segmented view switcher or any custom action.

Code

import {
  Button,
  CalendarNav,
  CalendarToday,
  Eventcalendar,
  getJson,
  Segmented,
  SegmentedGroup,
  setOptions ,
} from '@mobiscroll/react';
import { useCallback, useEffect, useState } from 'react';

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

function App() {
  const [myEvents, setEvents] = useState([]);
  const [currentDate, setCurrentDate] = useState(new Date());
  const [currentView, setCurrentView] = useState('agenda');
  const [myView, setView] = useState({ agenda: { type: 'month' } });

  const handleSelectedDateChange = useCallback((args) => {
    setCurrentDate(args.date);
  }, []);

  const changeView = useCallback((event) => {
    let view;
    switch (event.target.value) {
      case 'calendar':
        view = {
          calendar: { type: 'month' },
        };
        break;
      case 'agenda':
        view = {
          agenda: { type: 'month' },
        };
        break;
    }

    setCurrentView(event.target.value);
    setView(view);
  }, []);

  const prevPage = useCallback(() => {
    setCurrentDate((currentDate) => new Date(currentDate.getFullYear(), currentDate.getMonth() - 1, 1));
  }, []);

  const nextPage = useCallback(() => {
    setCurrentDate((currentDate) => new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 1));
  }, []);

  const customWithNavButtons = useCallback(
    () => (
      <>
        <CalendarNav className="mds-custom-header-nav" />
        <div className="mbsc-flex mbsc-flex-1-0 mbsc-justify-content-center">
          <Button onClick={prevPage} icon="material-arrow-back" variant="flat" className="mds-custom-header-button"></Button>
          <CalendarToday />
          <Button onClick={nextPage} icon="material-arrow-forward" variant="flat" className="mds-custom-header-button"></Button>
        </div>
        <div className="mds-custom-header-switch">
          <SegmentedGroup value={currentView} onChange={changeView}>
            <Segmented value="agenda" icon="material-view-day" />
            <Segmented value="calendar" icon="calendar" />
          </SegmentedGroup>
        </div>
      </>
    ),
    [changeView, currentView, prevPage, nextPage],
  );

  useEffect(() => {
    getJson(
      'https://trial.mobiscroll.com/events/?vers=5',
      (events) => {
        setEvents(events);
      },
      'jsonp',
    );
  }, []);

  return (
    <Eventcalendar
      data={myEvents}
      renderHeader={customWithNavButtons}
      selectedDate={currentDate}
      view={myView}
      onSelectedDateChange={handleSelectedDateChange}
    />
  );
}

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.