onResourceToggle
Hears a person fold or unfold a resource or a group in the Pro’s timeline.
| Type | (state: { readonly collapsedResources: readonly string[]; readonly collapsedGroups: readonly string[] }) => void |
|---|---|
| Default | not set |
Live update (update()) | Yes |
| Declared in | packages/dom/src/settings.ts |
What it does
Section titled “What it does”It receives the whole state after the change — { collapsedResources, collapsedGroups } — not the one row toggled: store it as it comes, and give
it back as collapsedResources and collapsedGroups the next time, so the
timeline opens as the person left it. A change made by your code
(update({ collapsedResources })) is not reported.
Example
Section titled “Example”import { createCalendar } from '@dzcalendar/dom';import '@dzcalendar/pro';
const saved = JSON.parse(localStorage.getItem('tree') ?? '{}') as { collapsedResources?: string[]; collapsedGroups?: string[] };
createCalendar(element, { timeZone: 'Europe/Paris', initialView: 'resourceTimelineWeek', resources: [{ id: 'cardio', title: 'Cardiology' }, { id: 'benali', title: 'Dr Benali', parentId: 'cardio' }], ...saved, onResourceToggle: (state) => localStorage.setItem('tree', JSON.stringify(state)),});import { Component } from '@angular/core';import { DZ_CALENDAR } from '@dzcalendar/angular';import '@dzcalendar/pro';
@Component({ selector: 'app-planning', imports: [DZ_CALENDAR], template: `<dz-calendar timeZone="Europe/Paris" view="resourceTimelineWeek" [resources]="tree" [options]="{ onResourceToggle: keep }" />`,})export class Planning { readonly tree = [{ id: 'cardio', title: 'Cardiology' }, { id: 'benali', title: 'Dr Benali', parentId: 'cardio' }]; readonly keep = (state: { collapsedResources: readonly string[] }) => localStorage.setItem('folded', JSON.stringify(state.collapsedResources));}import { DzCalendar } from '@dzcalendar/react';import '@dzcalendar/pro';
const TREE = [{ id: 'cardio', title: 'Cardiology' }, { id: 'benali', title: 'Dr Benali', parentId: 'cardio' }];
export function Planning() { return ( <DzCalendar timeZone="Europe/Paris" defaultView="resourceTimelineWeek" resources={TREE} onResourceToggle={(state) => localStorage.setItem('tree', JSON.stringify(state))} /> );}<script setup lang="ts">import { DzCalendar } from '@dzcalendar/vue';import '@dzcalendar/pro';
const tree = [{ id: 'cardio', title: 'Cardiology' }, { id: 'benali', title: 'Dr Benali', parentId: 'cardio' }];const keep = (state: { collapsedResources: readonly string[] }) => localStorage.setItem('folded', JSON.stringify(state.collapsedResources));</script>
<template> <DzCalendar time-zone="Europe/Paris" view="resourceTimelineWeek" :resources="tree" :options="{ onResourceToggle: keep }" /></template>In Angular and Vue it goes in options; in React it is a prop.
See also
Section titled “See also”collapsedResources— the folded resources.collapsedGroups— the shut groups.- Resources & timeline.