---
title: "Javascript Calendar Week View Example | Mobiscroll"
component: "Calendar"
framework: "JavaScript"
library_version: "6.1.5"
url: "https://demo.mobiscroll.com/javascript/calendar/week-view"
---

# Week View - JavaScript Calendar demo

Display 1, 2, or 3 weeks inline in a Javascript date picker — switch between week and month views dynamically without recreating the component. Plain JS api for usage everywhere.

- [Live demo](https://demo.mobiscroll.com/javascript/calendar/week-view)
- [View code on GitHub](https://github.com/acidb/mobiscroll-demos-javascript/tree/main/src/demos/datepicker/calendar/week-view)
- This demo in other frameworks: [jQuery](https://demo.mobiscroll.com/jquery/calendar/week-view.md), [Angular](https://demo.mobiscroll.com/angular/calendar/week-view.md), [React](https://demo.mobiscroll.com/react/calendar/week-view.md), [Vue](https://demo.mobiscroll.com/vue/calendar/week-view.md)

## Description

Show a week calendar instead of a monthly calendar view to save space. By setting the [`calendarType`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-calendarType) to `'week'` and passing the count in the [`calendarSize`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-calendarSize) option you can simply enable a week view.

You can dynamically change the number of weeks or switch between month and week view without the need for recycling the whole component.

**Interested in switching week and month view?** [Learn how to set up switch inside the calendar →](https://demo.mobiscroll.com/javascript/calendar/week-to-month)

## What this demo shows

- This example demonstrate different ways to display one/two or three weeks of calendar for date selection.
- **Week count switcher** A segmented control above the date picker switches between one-, two-, and three-week layouts and updates the calendar view dynamically.
- **Dynamic view updates** The number of displayed weeks can change without recreating the date picker component.
- **Header navigation** The month and year label in the top left opens a month and year picker. The blue previous and next arrow buttons on the right navigate between weeks.
- **Week view** A fixed weekday header displays abbreviated day names from Sunday through Saturday, with the dates arranged in a grid below it.
- **Week navigation** The week can be changed by clicking and dragging the calendar left or right.
- **Day cell states** Hovering a day highlights the day number with a gray background. Selecting a day highlights the day number with a blue background. The current date is highlighted by default and remains blue when the user selects another date.

## Best for

- **Compact date selection** Forms, dialogs, and side panels where a full month calendar would use more space than needed.
- **Near-term booking** Appointment, reservation, and service-booking flows focused on availability over the next one to three weeks.
- **Short-range scheduling** Shift planning, task assignment, and resource scheduling where users work within a limited weekly window.
- **Adjustable planning horizons** Interfaces that let users switch between a focused single-week view and a broader two- or three-week overview.

## Tutorial

### Change the week count

- ( ) One week
- (x) Two weeks
- ( ) Three weeks

```js
mobiscroll.datepicker('#picker', {
    calendarType: 'week',
    calendarSize: 2
}
```

With "One week":

```js
mobiscroll.datepicker('#picker', {
    calendarType: 'week',
    calendarSize: 1
}
```

With "Three weeks":

```js
mobiscroll.datepicker('#picker', {
    calendarType: 'week',
    calendarSize: 3
}
```

## API used in this demo

- [`theme`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-theme) - option
- [`themeVariant`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-themeVariant) - option
- [`controls`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-controls) - option
- [`display`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-display) - option
- [`calendarType`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-calendarType) - option
- [`calendarSize`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-calendarSize) - option

## Code

### JS

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

mobiscroll.datepicker('#demo-1-week', {
  controls: ['calendar'],
  display: 'inline',
  calendarType: 'week',
  calendarSize: 1,
});

mobiscroll.datepicker('#demo-2-weeks', {
  controls: ['calendar'],
  display: 'inline',
  calendarType: 'week',
  calendarSize: 2,
});

mobiscroll.datepicker('#demo-3-weeks', {
  controls: ['calendar'],
  display: 'inline',
  calendarType: 'week',
  calendarSize: 3,
});
```

### HTML

```html
<div id="demo-1-week"></div>
<div id="demo-2-weeks"></div>
<div id="demo-3-weeks"></div>
```

## Implementation notes

- Use `controls: ['calendar']`, `display: 'inline'`, `calendarType: 'week'`, and `calendarSize: 2` as the starting (two-week) view - a single instance, not three separate calendars.
- `calendarSize` can be set to `1`, `2`, or `3` via `setOptions({ calendarSize })` to resize the same calendar dynamically without recreating the component.

## 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: [Date & Time Picker](https://demo.mobiscroll.com/javascript/calendar/date-time-picker.md) - Pick a date, time, or both with the Javascript date picker — choose from an inline calendar, scroller, or time grid in one component.
- Next: [Multiple Months](https://demo.mobiscroll.com/javascript/calendar/multiple-months.md) - Show fixed or auto-fit months in a Javascript calendar date picker — switch between month and week view.
