---
title: "JQuery Agenda Resource Filter in Header Example | Mobiscroll"
component: "Agenda"
framework: "jQuery"
library_version: "6.1.5"
url: "https://demo.mobiscroll.com/jquery/agenda/resource-filtering-in-header"
---

# Resource Filter in Header - jQuery Agenda demo

Embed a segmented resource filter in the JQuery Agenda custom header — filter displayed events by person or team.

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

## Description

The agenda doesn't have built in resource listing, however we can easily solve that inside the header using the segmented component. The header of the agenda is a canvas and an opportunity for customization. You can add custom components and enable new interaction in context.

Such an example would be a custom filter block created with the help of a segmented control and placed between the standard UI components, which are:

- **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`.

### 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 .mds-header-filter-prev { order: 1; }
            .mbsc-material .mds-header-filter-next { order: 2; }
            .mbsc-material .mds-header-filter { order: 3; }
            .mbsc-material .mds-header-filter-today { order: 4; }
```

**Want to style and reorder the header?** [Take a look at the previous example →](https://demo.mobiscroll.com/jquery/agenda/customizing-calendar-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. A segmented resource filter is centered in the header. The previous and next arrows and the Today button on the right move between months and jump back to the current date.
- **Resource filter** The segmented control contains three selectable options: `Barry`, `Hortense`, and `Carl`, each with an avatar shown before the name.
- **Resource filtering** Selecting a resource from the segmented control, updates the month view to show that person's events, making it possible to show or hide events by resource from the header.
- **Color coding** `Barry`'s option and events use green, `Hortense` uses blue, and `Carl` uses pink, so the active filter and the visible events stay visually aligned.
- **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.

## Best for

- **Resource-specific month planning** Viewing one person's month schedule at a time without leaving the agenda view.
- **Team agendas with simple filtering** Switching between a small set of people or resources from a compact header control.
- **Color-coded resource views** Making it easy to distinguish which events belong to which resource.
- **Operational dashboards** Internal scheduling tools where users need quick filtering and fast month-to-month navigation.
- **Custom agenda toolbars** Cases where the standard header needs extra controls without moving filtering outside the agenda.

## API used in this demo

- [`theme`](https://mobiscroll.com/docs/jquery/eventcalendar/api#opt-theme) - option
- [`themeVariant`](https://mobiscroll.com/docs/jquery/eventcalendar/api#opt-themeVariant) - option
- [`view`](https://mobiscroll.com/docs/jquery/eventcalendar/api#opt-view) - option
- [`resources`](https://mobiscroll.com/docs/jquery/eventcalendar/api#opt-resources) - option
- [`renderHeader`](https://mobiscroll.com/docs/jquery/eventcalendar/api#renderer-renderHeader) - renderer
- [`setEvents`](https://mobiscroll.com/docs/jquery/eventcalendar/api#method-setEvents) - method

## Code

### JS

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

$(function () {
  var myEvents = [];

  var myResources = [
    { id: 1, name: 'Barry', color: '#328e39', img: 'https://img.mobiscroll.com/demos/m1.png' },
    { id: 2, name: 'Hortense', color: '#00aabb', img: 'https://img.mobiscroll.com/demos/f1.png' },
    { id: 3, name: 'Carl', color: '#ea72c0', img: 'https://img.mobiscroll.com/demos/m2.png' },
  ];

  var selectedResources = { 1: true };

  var calendar = $('#demo-header-filter')
    .mobiscroll()
    .eventcalendar({
      view: {
        agenda: { type: 'month' },
      },
      resources: myResources,
      renderHeader: function () {
        var header = '<div mbsc-calendar-nav class="mds-header-filter-nav"></div>' + '<div class="mds-header-filter mbsc-flex-1-0">';

        myResources.forEach(function (res) {
          header +=
            '<label class="mds-header-filter-' +
            res.id +
            '">' +
            '<img class="mds-header-filter-img" src="' +
            res.img +
            '"/>' +
            '<span class="mds-header-filter-name">' +
            res.name +
            '</span>' +
            '<input type="checkbox" mbsc-segmented name="resource" class="mds-header-filter-input" value="' +
            res.id +
            '" ' +
            (res.id === 1 ? 'checked' : '') +
            '>' +
            '</label>';
        });

        header +=
          '</div>' +
          '<button mbsc-calendar-prev class="mds-header-filter-prev"></button>' +
          '<button mbsc-calendar-today class="mds-header-filter-today"></button>' +
          '<button mbsc-calendar-next class="mds-header-filter-next"></button>';
        return header;
      },
    })
    .mobiscroll('getInst');

  $.getJSON('https://trial.mobiscroll.com/filter-resource-events/?callback=?', function (events) {
    myEvents = events;
    var filteredEvents = myEvents.filter(function (e) {
      return selectedResources[e.resource];
    });
    calendar.setEvents(filteredEvents);
  });

  $('.mds-header-filter-input').on('change', function (ev) {
    var value = +ev.target.value;
    var checked = ev.target.checked;

    selectedResources[value] = checked;

    var resource = myResources.find(function (r) {
      return r.id === value;
    });
    var filteredEvents = myEvents.filter(function (e) {
      return selectedResources[e.resource];
    });

    calendar.setEvents(filteredEvents);

    mobiscroll.toast({
      message: (checked ? 'Showing ' : 'Hiding ') + (resource ? resource.name : '') + ' events',
    });
  });
});
```

### HTML

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

### CSS

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

.mds-header-filter-img {
  width: 25px;
}

.mds-header-filter-name {
  margin-left: 10px;
}

.mds-header-filter .mbsc-segmented {
  max-width: 400px;
  margin: 0 auto;
}

.mds-header-filter .mbsc-segmented-button.mbsc-selected {
  color: #fff;
}

.mds-header-filter-1 .mbsc-button.mbsc-selected.mbsc-material,
.mds-header-filter-1 .mbsc-button.mbsc-selected.mbsc-windows,
.mds-header-filter-1 .mbsc-segmented-selectbox-inner {
  background: #328e39;
}

.mds-header-filter-2 .mbsc-button.mbsc-selected.mbsc-material,
.mds-header-filter-2 .mbsc-button.mbsc-selected.mbsc-windows,
.mds-header-filter-2 .mbsc-segmented-selectbox-inner {
  background: #00aabb;
}

.mds-header-filter-3 .mbsc-button.mbsc-selected.mbsc-material,
.mds-header-filter-3 .mbsc-button.mbsc-selected.mbsc-windows,
.mds-header-filter-3 .mbsc-segmented-selectbox-inner {
  background: #ea72c0;
}

.mbsc-material .mds-header-filter-prev {
  order: 1;
}

.mbsc-material .mds-header-filter-next {
  order: 2;
}

.mbsc-material .mds-header-filter {
  order: 3;
}

.mbsc-material .mds-header-filter-today {
  order: 4;
}
```

## Implementation notes

- Use `view: { agenda: { type: 'month' } }`. Define a `resources` array with 3 entries - each has `id`, `name`, `color`, and `img` (avatar URL). Pass it to the `resources` option. Load events from `https://trial.mobiscroll.com/filter-resource-events/` via JSONP using `getJson(url, callback, 'jsonp')`. Angular: use `HttpClient.jsonp()`. Each event has a `resource` field (integer ID) that links it to a resource.
- Implement client-side filtering: maintain a `selectedResources` set (initially resource 1 only). After loading, compute `filteredEvents = myEvents.filter(e => selectedResources[e.resource])` and pass `filteredEvents` to the Eventcalendar's `data` option. Recompute and update `filteredEvents` whenever the selection changes.
- Build a custom header via `renderHeader` (Angular: `headerTemplate`, Vue: `header` slot) containing: `CalendarNav` on the left, a `SegmentedGroup` with `select="multiple"` in the center (each `Segmented` shows the resource's avatar image + name), and `CalendarPrev`, `CalendarToday`, `CalendarNext` on the right. On segment change, update the `selectedResources` map and refresh `filteredEvents`. Show a Toast with "Showing/Hiding {name} events".

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

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

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