Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

  • FilterBuilder and RelativeDate rendering

    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.
    Click image for larger version

Name:	filterbuilder.PNG
Views:	1
Size:	15.5 KB
ID:	254249
    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);
        }
    }

  • #2
    We've made a change to address this in builds dated July 31 and later - when allowAbsoluteDates is false, as it is in your test-case, you should now see the behavior you expect.

    Comment


    • #3
      Ok, I will wait for the 20180731 nightly to become available, confirm and report back. Thanks.

      Comment


      • #4
        Confirmed that this behavior is working as expected now (I have the 2018-08-04 nightly).

        Comment

        Working...
        X