SmartClient Version: v11.1p_2018-03-28/Pro Deployment (built 2018-03-28)
I am trying to persist and restore settings for a FilterBuilder.
Using other posts on the site I've been able to convert the AdvancedCriteria to JSON, store as a String (that I could persist to a db) and then restore the FilterBuilder contents from the JSON. This works as I expect, with the exception that when RelativeDate is restored, if I've specified the filter as "less than" "N days from now" "30", I want this 3-form-item format restored in the filter when I plug the JSON back in. Currently the widget converts the relative date to an actual date and populates it in a SelectItem which is not what I want.
The attachment shows both formats, I'd like the top (highlighted) format to be restored, not the bottom format (which is currently what happens).
Should I be modifying the defaults of RelativeDateItem to achieve this? I can't seem to find the right settings.
Thanks.
I am trying to persist and restore settings for a FilterBuilder.
Using other posts on the site I've been able to convert the AdvancedCriteria to JSON, store as a String (that I could persist to a db) and then restore the FilterBuilder contents from the JSON. This works as I expect, with the exception that when RelativeDate is restored, if I've specified the filter as "less than" "N days from now" "30", I want this 3-form-item format restored in the filter when I plug the JSON back in. Currently the widget converts the relative date to an actual date and populates it in a SelectItem which is not what I want.
The attachment shows both formats, I'd like the top (highlighted) format to be restored, not the bottom format (which is currently what happens).
Should I be modifying the defaults of RelativeDateItem to achieve this? I can't seem to find the right settings.
Thanks.
Code:
public class FilterBuilderDemo extends Tab { private String filterString; public FilterBuilderDemo() { super("Product Filter Builder"); // Enforce how RelativeDateItem is rendered in FilterBuilder RelativeDateItem defaults = new RelativeDateItem(); defaults.setTimeUnitOptions(TimeUnit.DAY, TimeUnit.WEEK, TimeUnit.MONTH, TimeUnit.YEAR); defaults.setAllowAbsoluteDates(false); RelativeDateItem.setDefaultProperties(defaults); final FilterBuilder filters = new FilterBuilder(); filters.setFieldDataSource(DataSource.get("productFilterDS")); IButton save = new IButton("Save"); save.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { filterString = filters.getCriteria().toJSON(); filters.getCriteria().asString(); SC.say("JSON<br>" + filterString); filters.clearCriteria(); } }); IButton restore = new IButton("Restore"); restore.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (filterString != null) { filters.setCriteria(AdvancedCriteria.fromJSON(filterString)); } } }); VLayout content = new VLayout(); content.addMember(filters); content.addMember(save); content.addMember(restore); setPane(content); } }
Comment