Hi Isomorphic,
when revisiting old code I found a feature I build a few years ago, but that I could not use because of this now long fixed bug.
What I'm doing is adding a CanvasItem after my MiniDateRangeItem, that consists of some Labels that quick-fill the Item for filtering on click.
As this is after my normal item I have to change the DynamicForms numCols to 3 and the colSpan of other items to 2. This would not be necessary if this was built-in.
This is what it looks like:
After click on Q2:
My suggestion is that you add options to MiniDateRangeItem and DateRangeItem to enable either predefined or custom "quick fillers".
This is what I did in SmartGWT:
I think this would make a nice addition. What do you think?
Best regards
Blama
when revisiting old code I found a feature I build a few years ago, but that I could not use because of this now long fixed bug.
What I'm doing is adding a CanvasItem after my MiniDateRangeItem, that consists of some Labels that quick-fill the Item for filtering on click.
As this is after my normal item I have to change the DynamicForms numCols to 3 and the colSpan of other items to 2. This would not be necessary if this was built-in.
This is what it looks like:
After click on Q2:
My suggestion is that you add options to MiniDateRangeItem and DateRangeItem to enable either predefined or custom "quick fillers".
- Predefined could be: YTD, QTD, MTD, WTD, Last year, Last quater, Last Month, Last Week, Next year, Next quater, Next Month, Next Week.
I don't have the future options there, as this is a creation date (=in the past). But generally, past and future are useful of course. - Manually they'd consist of an array of entries consisting of a title and a from/to-Date or RelativeDateString.
This is what I did in SmartGWT:
Code:
MiniDateRangeItem createdAtDRI = new MiniDateRangeItem("CREATED_AT", I18nEdited.creationDateRange()); createdAtDRI.setType("datetime"); createdAtDRI.setAllowRelativeDates(true); createdAtDRI.setWidth("*"); availableFields.add(createdAtDRI); availableFields.add(new MDRIConfiguer("MDRIConfiguer", createdAtDRI)); setFields(availableFields.toArray(new FormItem[availableFields.size()])); MDRIConfiguer.java: public class MDRIConfiguer extends CanvasItem { private MiniDateRangeItem createdAtDRI; public MDRIConfiguer(String name, final MiniDateRangeItem createdAtDRI) { super(name); this.createdAtDRI = createdAtDRI; setShouldSaveValue(false); setStartRow(false); setShowTitle(false); setWidth("*"); setHeight(1); HStack al = new HStack(5); { al.addMember(new DateShortcut("YTD", new RelativeDate("-0Y[-0Y]"), null)); al.addMember(new DateShortcut("QTD", new RelativeDate("-0Q[-0Q]"), null)); al.addMember(new DateShortcut("MTD", new RelativeDate("-0M[-0M]"), null)); Date d = new Date(); DateTimeFormatInfo ddtfi = LocaleInfo.getCurrentLocale().getDateTimeFormatInfo(); CalendarUtil.addMonthsToDate(d, -12); String lastYear = DateTimeFormat.getFormat(ddtfi.formatYear()).format(d); d = new Date(); CalendarUtil.addMonthsToDate(d, -3); int month0aligned = (new Integer(DateTimeFormat.getFormat("M").format(d)) / 3) + 1; String lastQuarter = "Q" + (month0aligned == 0 ? 4 : month0aligned); d = new Date(); CalendarUtil.addMonthsToDate(d, -1); String lastMonth = DateTimeFormat.getFormat(ddtfi.formatMonthFull()).format(d); al.addMember(new DateShortcut(lastYear, new RelativeDate("-1Y[-0Y]"), new RelativeDate("-1Y[+0Y]"))); al.addMember(new DateShortcut(lastQuarter, new RelativeDate("-1Q[-0Q]"), new RelativeDate("-1Q[+0Q]"))); al.addMember(new DateShortcut(lastMonth, new RelativeDate("-1M[-0M]"), new RelativeDate("-1M[+0M]"))); } setCanvas(al); } private class DateShortcut extends Label { public DateShortcut(String content, final RelativeDate startRD, final RelativeDate endRD) { super(); setWidth(1); setCursor(Cursor.HAND); setContents("<span style=\"text-decoration: underline;\">" + content + "</span>"); addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { DateRange dr = new DateRange(); dr.setRelativeStartDate(startRD); if (endRD != null) dr.setRelativeEndDate(endRD); createdAtDRI.setValue(dr); } }); } } }
Best regards
Blama
Comment