---
title: "Javascript Agenda Event Calendar Agenda Custom Header Example | Mobiscroll"
component: "Agenda"
framework: "JavaScript"
library_version: "6.1.5"
url: "https://demo.mobiscroll.com/javascript/agenda/customizing-calendar-header"
---

# Event Calendar Agenda Custom Header - JavaScript Agenda demo

Build a custom Javascript event calendar agenda header — rearrange navigation controls, add a view switcher, and control layout per theme. Plain JS api for usage everywhere.

- [Live demo](https://demo.mobiscroll.com/javascript/agenda/customizing-calendar-header)
- [View code on GitHub](https://github.com/acidb/mobiscroll-demos-javascript/tree/main/src/demos/eventcalendar/agenda/customizing-calendar-header)
- This demo in other frameworks: [jQuery](https://demo.mobiscroll.com/jquery/agenda/customizing-calendar-header.md), [Angular](https://demo.mobiscroll.com/angular/agenda/customizing-calendar-header.md), [React](https://demo.mobiscroll.com/react/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/javascript/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** - `<div mbsc-calendar-nav></div>`. Use the `.md-header-filter-controls` CSS class for custom overrides.
- **Today button** - `<button mbsc-calendar-today></button>`. Use the `.md-header-filter-today` CSS class for custom overrides.
- **Previous month button** - `<button mbsc-calendar-prev></button>`. Use the `.md-header-filter-prev` CSS class for custom overrides.
- **Next month button** - `<button mbsc-calendar-next></button>`. 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/javascript/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/javascript/eventcalendar/api#opt-theme) - option
- [`themeVariant`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-themeVariant) - option
- [`view`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-view) - option
- [`onSelectedDateChange`](https://mobiscroll.com/docs/javascript/eventcalendar/api#event-onSelectedDateChange) - event
- [`renderHeader`](https://mobiscroll.com/docs/javascript/eventcalendar/api#renderer-renderHeader) - renderer
- [`setOptions`](https://mobiscroll.com/docs/javascript/eventcalendar/api#method-setOptions) - method
- [`navigate`](https://mobiscroll.com/docs/javascript/eventcalendar/api#method-navigate) - method
- [`setEvents`](https://mobiscroll.com/docs/javascript/eventcalendar/api#method-setEvents) - method

## Code

### JS

```js
mobiscroll.setOptions({
  theme: 'ios',
  themeVariant: 'light'
});

var currentDate = new Date();

var calendar = mobiscroll.eventcalendar('#demo-custom-header', {
  view: { agenda: { type: 'month' } },
  onSelectedDateChange: function (args) {
    currentDate = args.date;
  },
  renderHeader: function () {
    return (
      '<div mbsc-calendar-nav class="mds-custom-header-nav"></div>' +
      '<div class="mbsc-flex mbsc-flex-1-0 mbsc-justify-content-center">' +
      '<button id="demo-custom-header-prev" mbsc-button data-variant="flat" data-icon="material-arrow-back" class="mds-custom-header-button"></button>' +
      '<button mbsc-calendar-today></button>' +
      '<button id="demo-custom-header-next" mbsc-button data-variant="flat" data-icon="material-arrow-forward" class="mds-custom-header-button"></button>' +
      '</div>' +
      '<div class="mds-custom-header-switch">' +
      '<label><input data-icon="material-view-day" mbsc-segmented type="radio" name="view" value="agenda" class="mds-custom-header-view-change" checked></label>' +
      '<label><input data-icon="calendar" mbsc-segmented type="radio" name="view" value="calendar" class="mds-custom-header-view-change"></label>' +
      '</div>'
    );
  },
});

document.querySelectorAll('.mds-custom-header-view-change').forEach(function (elm) {
  elm.addEventListener('change', function (ev) {
    switch (ev.target.value) {
      case 'calendar':
        calendar.setOptions({
          view: { calendar: { type: 'month' } },
        });
        break;
      case 'agenda':
        calendar.setOptions({
          view: { agenda: { type: 'month' } },
        });
        break;
    }
  });
});

document.getElementById('demo-custom-header-prev').addEventListener('click', function () {
  currentDate = new Date(currentDate.getFullYear(), currentDate.getMonth() - 1, 1);
  calendar.navigate(currentDate);
});

document.getElementById('demo-custom-header-next').addEventListener('click', function () {
  currentDate = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 1);
  calendar.navigate(currentDate);
});

mobiscroll.getJson(
  'https://trial.mobiscroll.com/events/?vers=5',
  function (events) {
    calendar.setEvents(events);
  },
  'jsonp',
);
```

### HTML

```html
<div id="demo-custom-header"></div>
```

### 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-javascript.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 javascript
   ```

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 javascript --trial`.

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

## Related demos

- Previous: [Full Event Customization](https://demo.mobiscroll.com/javascript/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/javascript/agenda/customizing-day-header.md) - Build customizable Javascript agenda day headers — style date labels and add per-day action buttons, including headers for days without events.
