getEvents
Returns the calendar's event list. With no arguments it returns every stored event. With start and end, it returns only events that overlap that range.
Usage
getEvents(start?: Date, end?: Date): CalendarEvent[];
Parameters:
| Parameter | Type | Description |
|---|---|---|
start | Date | Optional range start. Returns events ending at or after this date. |
end | Date | Optional range end. Returns events starting at or before this date. |
Returns: CalendarEvent[].
| Field | Type | Description |
|---|---|---|
id | string | number | Unique event id. |
start | Date | Event start time. |
end | Date | Event end time. |
allDay | boolean | Optional. All-day flag. |
[key] | any | Custom fields preserved on the event. |
When recurring is enabled, the returned list contains expanded occurrences, not master events.
Example
<script lang="ts">
import { Calendar } from "@wx/svelte-calendar";
import type { CalendarInstanceApi } from "@wx/svelte-calendar";
let api = $state<CalendarInstanceApi>();
function exportAll() {
const all = api.getEvents();
console.log(all);
}
function exportThisWeek() {
const start = new Date();
const end = new Date();
end.setDate(start.getDate() + 7);
const events = api.getEvents(start, end);
console.log(events);
}
</script>
<Calendar {events} bind:this={api} />
<button onclick={exportAll}>All events</button>
<button onclick={exportThisWeek}>This week</button>
Related articles
getEvent— look up a single event by id.events— the source array.recurring— when enabled, this method returns expanded instances.serializeICal— pair withgetEvents()to export as.ics.- Import and export — round-trip events through iCal or JSON.