Range Calendar: Get first and last displayed date #1941
|
I have a range calendar that I want to get the first and last date from to make a backend query with that date range. Does RangeCalendar expose any information on the date range it displays? I have looked at this post which mentions a monthsVisible. That property is no available on the rangeCalendar, though. |
Replies: 1 comment
|
The <RangeCalendar.Root bind:placeholder>
{#snippet children({ months, weekdays })}
{@const firstVisible = months[0].weeks[0][0]}
{@const lastVisible = months.at(-1).weeks.at(-1).at(-1)}
<!-- render the calendar as usual -->
{/snippet}
</RangeCalendar.Root>The cells are |
The
childrensnippet ofRangeCalendar.Rootexposesmonths, and the visible bounds are its ends. Each month object carries its renderedweeks, including the leading and trailing cells that belong to the neighbouring months, so the first cell of the first week and the last cell of the last week are exactly what the user sees:The cells are
@internationalized/dateobjects, sofirstVisible.toString()gives you an ISO date for the backe…