---
title: "React Agenda Custom Header Example | Mobiscroll"
component: "Agenda"
framework: "React"
library_version: "6.1.5"
url: "https://demo.mobiscroll.com/react/agenda/customizing-calendar-header"
---

# Custom Header - React Agenda demo

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

- [Live demo](https://demo.mobiscroll.com/react/agenda/customizing-calendar-header)
- [View React JS code on GitHub](https://github.com/acidb/mobiscroll-demos-react/tree/main/src/demos/eventcalendar/agenda/customizing-calendar-header)
- [View React TS code on GitHub](https://github.com/acidb/mobiscroll-demos-react-ts/tree/main/src/demos/eventcalendar/agenda/customizing-calendar-header)
- This demo in other frameworks: [JavaScript](https://demo.mobiscroll.com/javascript/agenda/customizing-calendar-header.md), [jQuery](https://demo.mobiscroll.com/jquery/agenda/customizing-calendar-header.md), [Angular](https://demo.mobiscroll.com/angular/agenda/customizing-calendar-header.md), [Vue](https://demo.mobiscroll.com/vue/agenda/customizing-calendar-header.md)

## Description

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`](https://mobiscroll.com/docs/react/eventcalendar/api#renderer-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](https://css-tricks.com/snippets/css/a-guide-to-flexbox/) 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.:

```css
.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 →](https://demo.mobiscroll.com/react/agenda/resource-filtering-in-header)

## What this demo shows

- Shows a monthly agenda view with events listed and grouped by date.
- **Header navigation** The month and year label in the top left opens date navigation. The center contains previous and next month navigation arrows with a blue `Today` button between them for jumping back to the current date. The right side contains a segmented control with a list icon selected by default and a calendar icon for switching views.
- **Agenda list** The area below the header lists events for the selected month. Events in the agenda are grouped by date.
- **Sticky day headers** As the agenda scrolls vertically, each day stays visible with a sticky date header while its events appear underneath.
- **Events:** Events appear as agenda cards with a colored strip on the left and the event title next to it. Start and end times are stacked on the right side of timed events. All-day events show the all-day label on the right.
- **Event interaction** Hovering an event highlights it.
- **Event selection** Clicking an event selects and highlights it.
- **Event calendar view** Selecting the calendar option from the segmented control switches the layout to a monthly calendar view.
- **Event labels** Days with events display labels directly inside the month cells. Labels use different styles and colors to distinguish all-day events, multi-day, and timed events.
- **Overflow handling** The number of visible event labels depends on the available vertical space in the day cell. Additional events are moved into a popover and indicated by an `X more` label, where `X` represents the number of hidden events. Clicking it opens a popover that lists the remaining events for that day.
- **Label interaction** Hovering over or clicking an event label selects it and highlights the selected label. This is tru in both views, event calendar month view and the scheduler week view.
- **Day cell states** Hovering a day cell highlights the day number with a gray background, while clicking the empty part of the cell selects the day and highlights the day number with a blue background.
- **Month navigation** The month can be changed by clicking and dragging the calendar left or right.

## Best for

- **Calendar and agenda switching** Interfaces where users need to move between a month overview for agenda and event calendar from the same header control.
- **Desktop planning tools** Scheduling and planning screens designed for desktop use, where a full month grid and richer header controls fit naturally.

## API used in this demo

- [`theme`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-theme) - option
- [`themeVariant`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-themeVariant) - option
- [`data`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-data) - option
- [`renderHeader`](https://mobiscroll.com/docs/react/eventcalendar/api#renderer-renderHeader) - renderer
- [`selectedDate`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-selectedDate) - option
- [`view`](https://mobiscroll.com/docs/react/eventcalendar/api#opt-view) - option
- [`onSelectedDateChange`](https://mobiscroll.com/docs/react/eventcalendar/api#event-onSelectedDateChange) - event

## Code

### JSX

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

setOptions({
  theme: 'ios',
  themeVariant: 'light'
});

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;
```

### TSX

```tsx
import {
  Button,
  CalendarNav,
  CalendarToday,
  Eventcalendar,
  getJson,
  MbscCalendarEvent,
  MbscEventcalendarView,
  MbscSelectedDateChangeEvent,
  Segmented,
  SegmentedGroup,
  setOptions,
} from '@mobiscroll/react';
import { ChangeEvent, FC, useCallback, useEffect, useState } from 'react';

setOptions({
  theme: 'ios',
  themeVariant: 'light'
});

const App: FC = () => {
  const [currentDate, setCurrentDate] = useState(new Date());
  const [currentView, setCurrentView] = useState<string>('agenda');
  const [myEvents, setEvents] = useState<MbscCalendarEvent[]>([]);
  const [myView, setView] = useState<MbscEventcalendarView>({ agenda: { type: 'month' } });

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

  const changeView = useCallback((event: ChangeEvent<HTMLInputElement>) => {
    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, nextPage, prevPage, currentView],
  );

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

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

export default App;
```

### CSS

```css
.mds-custom-header-nav {
  width: 180px;
}

.mds-custom-header-button.mbsc-button {
  font-size: 20px;
  height: auto;
  padding: 0;
  margin: 0;
}

.mds-custom-header-switch .mbsc-segmented {
  width: 110px;
  margin-top: 0;
  margin-bottom: 0;
}

.mds-custom-header-switch .mbsc-segmented.mbsc-material,
.mds-custom-header-switch .mbsc-segmented.mbsc-windows {
  padding: 0;
}

.mds-custom-header-switch .mbsc-segmented-button.mbsc-button {
  font-size: 20px;
  height: 32px;
  padding: 0;
}
```

## Implementation notes

- Use `renderHeader` (React/JS/jQuery) / `headerTemplate` (Angular) / `header` slot (Vue) to replace the default header. Assemble it from the built-in nav components: `CalendarNav` (navigation label), `CalendarToday` (today button), and custom prev/next `Button`s that shift `currentDate` by ±1 month. Place a `SegmentedGroup` at the far right with "agenda" and "calendar" segments to switch views.
- Keep `selectedDate` and `onSelectedDateChange` wired so that the custom prev/next buttons and the nav label stay in sync. On segment change, swap `view` between `{ agenda: { type: 'month' } }` and `{ calendar: { type: 'month' } }`.
- Load events from `https://trial.mobiscroll.com/events/?vers=5` via JSONP using `getJson(url, callback, 'jsonp')`. Angular: use `HttpClient.jsonp()` instead. JS/jQuery: call `inst.setEvents(events)` in the callback.

## Run it in your project

1. If not signed up yet, or don't own a license, you can [start a free trial](https://mobiscroll.com/starttrial).

2. Clone the repository:

   ```
   git clone https://github.com/acidb/mobiscroll-demos-react.git
   ```

3. If not installed yet, install the Mobiscroll CLI from NPM:

   ```
   npm install -g @mobiscroll/cli
   ```

4. Config Mobiscroll - open a terminal window in the root directory and run:

   ```
   mobiscroll config react
   ```

5. Install dependencies - open a terminal window in the root directory and run:

   ```
   npm install
   ```

6. Run the project:

   ```
   npm run dev
   ```

On a trial, add `--trial` to the config command: `mobiscroll config react --trial`.

Running a demo locally requires a Mobiscroll trial or a license; setup is per framework at https://mobiscroll.com/docs/react/getting-started/installation

## Related demos

- Previous: [Full Event Customization](https://demo.mobiscroll.com/react/agenda/full-event-customization.md) - Fully customize agenda event card layout — show images, location, participants, and custom fields in each event row.
- Next: [Customizable Day Headers](https://demo.mobiscroll.com/react/agenda/customizing-day-header.md) - Build customizable React agenda day headers — style date labels and add per-day action buttons, including headers for days without events.
