# Date Picker

Canonical page: https://www.adaptabletools.com/docs/handbook-cell-editors-date-picker

- A Date Picker is provided by AdapTable whenever a date cell is edited
- It is also used when filtering a date column
- The Date Picker is highly configurable and themable

The Date Picker is automatically used by default in AdapTable when **editing** all Date cells.

A Date cell is one where the [Cell Data Type](https://www.adaptabletools.com/docs/dev-guide-aggrid-cell-data-types/index.md) property for the column is `date`

It is also used when **filtering** any Date Column.

This can be changed by setting `showDatePicker` to _false_ in [Configuring Column Filters](https://www.adaptabletools.com/docs/handbook-column-filter-configuring/index.md)

The Date Picker is designed to be easily themable and can be heavily customised with CSS Variables.

## Value Parser

If the Column Definition in AG Grid has a `valueParser` (provided as a function), that will be invoked **before** setting the value for the cell.

This is useful because dates can be stored as strings, numbers or Date instances, but the value parser will be called with a `Date` instance.

- It's your responsibility to transform that value to the format required for persisting it to the grid
- We strongly recommend you specify a `colDef.valueParser` function

## Customising

The Date Picker is configured via `dateInputOptions` in [User Interface Options](https://www.adaptabletools.com/docs/technical-reference-ui/index.md).

### `useNativeInput`

Use the browser's date input instead of AdapTable's Date Picker

When `true`, date cells and date Filter inputs use the native HTML date control. The other Date Picker options below are then ignored.

```ts {4}
userInterfaceOptions: {
  dateInputOptions: {
    useNativeInput: true,
  },
},
```

### `dateFormat`

Format string for the date input field

ISO 8601 by default. This is the text shown in the input, not how the value is stored in the Grid — use a `valueParser` for that.

```ts {4}
userInterfaceOptions: {
  dateInputOptions: {
    dateFormat: 'dd MMM yyyy',
  },
},
```

### `locale`

Locale used to localise the Date Picker

Pass a locale object (the same shape used by the Date Picker). Controls month names, first day of week display, and similar chrome.

```ts {4}
userInterfaceOptions: {
  dateInputOptions: {
    locale: fr, // e.g. from `date-fns/locale`
  },
},
```

### `showWeekNumber`

Show a week-number column in the Date Picker

```ts {4}
userInterfaceOptions: {
  dateInputOptions: {
    showWeekNumber: true,
  },
},
```

### `showOutsideDays`

Show days that fall in the previous or next month

Set to `false` to show only days in the current month.

```ts {4}
userInterfaceOptions: {
  dateInputOptions: {
    showOutsideDays: false,
  },
},
```

### `datepickerButtons`

Buttons in the Date Picker footer, in display order

  `DatepickerButton[]`

Built-in buttons: `clear`, `close`, `today`, `tomorrow`, `yesterday`, `nextWorkday`, `prevWorkday`.

Layout tokens: `-` pushes following buttons to the right; `|` starts a new row. Pass `[]` to hide all buttons.

`nextWorkday` / `prevWorkday` honour [Holiday Calendars](https://www.adaptabletools.com/docs/dev-guide-tutorial-holiday-calendars/index.md).

```ts {4}
userInterfaceOptions: {
  dateInputOptions: {
    datepickerButtons: ['today', '-', 'yesterday', 'nextWorkday'],
  },
},
```

**Example: Date Picker Customising**

Customise the AdapTable Date Picker

- This demo shows some ways to customise the AdapTable Date Picker (see `adaptableOptions.ts`)
  - The default Buttons have been set to `Today`, `Yesterday` and `Next Workday`
  - Show Week Numbering is on
  - Days not in the current month are hidden

- Open the Date Picker in the Filter Bar for one of the Date columns and see how it looks

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Date Picker Variables',

  userInterfaceOptions: {
    dateInputOptions: {
      datepickerButtons: ['today', '-', 'yesterday', 'nextWorkday'],
      showWeekNumber: true,
      showOutsideDays: false,
    },
  },

  initialState: {
    Dashboard: {
      ModuleButtons: ['Theme'],
      Tabs: [
        {
          Name: 'Default',
          Toolbars: ['Theme'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'language',
            'created_at',
            'updated_at',
            'pushed_at',
            'description',
            'open_issues_count',
            'closed_issues_count',
            'open_pr_count',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

## Theming

The Date Picker can be fully styled - colours, look and feel, borders etc.

**Example: Date Picker Theming**

Theming the AdapTable Date Picker

- This demo shows how to theme the AdapTable Date Picker using CSS variables in `styles.css`

- Open the Date Picker in the Filter Bar for one of the Date columns and see how it looks

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template + shown below]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Date Picker Theming',
  initialState: {
    Dashboard: {
      ModuleButtons: ['Theme'],
      Tabs: [
        {
          Name: 'Default',
          Toolbars: ['Theme'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'language',
            'created_at',
            'updated_at',
            'pushed_at',
            'description',
            'open_issues_count',
            'closed_issues_count',
            'open_pr_count',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

**`src/styles.css`**

```css
/*  Date Picker Colors */

:root.ab--theme-light {
  --ab-cmp-datepicker__background: rgb(238, 238, 238);
  --ab-cmp-datepicker__selected-color: rgb(98, 0, 255);
  --ab-cmp-datepicker__selected-text-color: rgb(255, 255, 255);
  --ab-cmp-datepicker__selected-border-radius: 30%;
  --ab-cmp-datepicker__day-border-radius: 30%;
  --ab-cmp-datepicker__border: 1px solid rgb(0, 4, 250);
  --ab-cmp-datepicker__cell-size: 40px;
}

:root.ab--theme-dark {
  --ab-cmp-datepicker__background: rgb(41, 0, 88);
  --ab-cmp-datepicker__selected-color: rgb(213, 187, 255);
  --ab-cmp-datepicker__selected-text-color: rgb(255, 255, 255);
  --ab-cmp-datepicker__selected-border-radius: 30%;
  --ab-cmp-datepicker__day-border-radius: 30%;
  --ab-cmp-datepicker__border: 1px solid rgb(0, 4, 250);
  --ab-cmp-datepicker__cell-size: 40px;
}
```

## Date Input Options

The options above cover the most common Date Picker settings.

The full property list for `dateInputOptions` is below.

The `dateInputOptions` class in [`UserInterfaceOptions`](https://www.adaptabletools.com/docs/reference/userinterfaceoptions.md) contains many properties for managing the Date Picker:

| Property | Type | Description | Default |
| --- | --- | --- | --- |
| [dateFormat](https://www.adaptabletools.com/docs/reference/dateinputoptions.md#dateformat) | `string` | Format string for formatting date input field | &#39;yyyy-MM-dd&#39; (ISO 8601 format) |
| [datepickerButtons](https://www.adaptabletools.com/docs/reference/dateinputoptions.md#datepickerbuttons) | `DatepickerButton[]` | List of buttons which are displayed in the datepicker overlay in the given order (provide empty array to display no buttons); custom button layout and positioning is achievable with the special elements `-` and `\|` | [&#39;close&#39;,&#39;today&#39;] |
| [locale](https://www.adaptabletools.com/docs/reference/dateinputoptions.md#locale) | `any` | Locale object (to localize Date Picker) | `en-US` |
| [showOutsideDays](https://www.adaptabletools.com/docs/reference/dateinputoptions.md#showoutsidedays) | `boolean` | Display outside days (i.e. those falling in next or previous month) | true |
| [showWeekNumber](https://www.adaptabletools.com/docs/reference/dateinputoptions.md#showweeknumber) | `boolean` | Display the week numbers column | false |
| [useNativeInput](https://www.adaptabletools.com/docs/reference/dateinputoptions.md#usenativeinput) | `boolean` | Use browser specific date input instead of AdapTable&#39;s Date Picker | false |
