daterange
Period selector for dashboards with presets in the language of the page, a calendar for custom ranges, the comparison with the previous period and an inline mode
Chooses the period of a dashboard: a preset (today, 7 days, this month...) or any range in the calendar, and optionally the comparison with the previous period. It is a button with a dropdown, or with inline:true a calendar that is always visible (a sidebar of filters).
The model is an Object:
{
from: Date, // the first day (00:00 local time)
to: Date, // the last day, included (00:00 local time)
preset: 'last30', // the preset, or '' for a custom range
compare: true, // the comparison is on
previous: { from: Date, to: Date } // the period before with the same length; null without the comparison
}- To set the period from the code,
{ preset: 'last7' }is enough, or{ from, to }withDateobjects oryyyy-MM-ddstrings. The component always writes the full object. - An empty model takes the
presetof the configuration once, so the dashboard has a period from the start. - The previous period has the same length just before;
month,lastmonth,yearandlastyearkeep the calendar shape (this month until today is compared with the same days of the month before). - Presets:
today,yesterday,lastN(any count of days:last7,last30,last90...),month,lastmonth,year,lastyear. Their names come fromIntlin the language of the page ("Today", "Hoy", "Heute", "30 days"...), so they need no translation;labelsreplaces them. - The week starts on the first day of the locale (
Intl.Localeweek info), or onfirstday. - Keyboard: the button opens the panel on the selected preset; in the calendar the arrows move by day and week,
PageUp/PageDownby month,Home/Endto the start and end of the week,Enterchooses the first and then the last day;Escapecancels the range in progress or closes the panel. Clicking outside closes it too.
Configuration:
label {String}the accessible name of the selector, example:Period(default:'')presets {String}the presets in the list, separated with commas; empty shows only the calendar (default:today,yesterday,last7,last30,last90,month,lastmonth,year)preset {String}the preset of an empty model; empty leaves the model empty (default:last30)labels {String}names of the presets separated with|, in the order ofpresets; empty uses the names ofIntl(default:'')compare {String}the text of the option to compare with the previous period, example:Compare with the previous period; empty hides it (default:'')inline {Boolean}the panel is always visible, without the button (default:false)future {Boolean}allows days after today (default:false)firstday {Number}the first day of the week,0is Sunday and1Monday; empty is the one of the locale (default:'')locale {String}a language for the names and dates, example:es-ES; empty is the language of the page (default:'')disabled {Boolean}disables the selector (default:false)
Callbacks:
change {String}link to a globalfunction(value, component), executed after a change by the user (a preset, a custom range or the comparison);valueis the model
Runtime: jComponent v20, no dependencies.




