Announcement

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

    Programmatically set filter BETWEEN in ListGrid

    I am using a ListGrid with a filter editor. In this filter editor I have a column that uses filter operators. As default operator it has LESS_OR_EQUAL, but also allows GREATER_OR_EQUAL and IBETWEEN_INCLUSIVE. On our website we offer the ability to save search criterias in the filter editor and then load them in. When trying to load a criteria that uses IBETWEEN_INCLUSIVE, the value does not display in the filter editor. This is because it is not set into the listGrid properly. How should I do to load the IBETWEEN_INCLUSIVE criteria into the filter editor/listgrid properly?

    When running the following code:

    Code:
    for (Criterion criterion : toSet.getCriteria()) {
        GWT.log(criterion.getFieldName() + ": " + criterion.getOperator() + ": " + criterion.getValueAsString());
    }
    
    wcuTable.setFilterEditorCriteria(toSet);
    
    for (Criterion criterion : table.getFilterEditorCriteriaAsAdvancedCriteria().getCriteria()) {
        GWT.log(criterion.getFieldName() + ": " + criterion.getOperator() + ": " + criterion.getValueAsString());
    }
    where toSet is an AdvancedCriteria containing the values I hope to set; I get the following:
    Code:
    wcuConnectionTime: IBETWEEN_INCLUSIVE: 772700...780711
    *13:33:53.320:WARN:Log:Uncaught exception escaped: com.google.gwt.core.client.JavaScriptException
    (TypeError) : Cannot read property 'getCriteria_13_g$' of null
        at run_26_g$(FastePortal-0.js@131:367038)
        at fire_0_g$(FastePortal-0.js@8:26628)
        at anonymous(FastePortal-0.js@16:26585)
        at apply_40_g$(FastePortal-0.js@28:28576)
        at entry0_0_g$(FastePortal-0.js@16:28632)
        at anonymous(FastePortal-0.js@14:28612)
    Clearly the data is in the AdvancedCriteria that is set, and the proper FilterOperator is also chosen, but for some reason it fails to load the value.

    This is the function used to generate the first DataSource Instance to allow filter operators to work:
    Code:
    private DataSource getClientDataSourceWithFields() {
            DataSource ds = new DataSource();
            int i = 0;
            ds.setClientOnly(true);
    
            DataSourceField[] dataSourceFields = new DataSourceField[VehiclesPanelColumn.values().length];    
            for ( VehiclesPanelColumn column : VehiclesPanelColumn.values()) {
                DataSourceField dataSourceField;
                if(column.equals(VehiclesPanelColumn.WCU_CONNECTION_TIME)) { // This is the column in question
                    dataSourceField = new DataSourceField(
                            column.getAttribute(),
                            FieldType.INTEGER,
                            column.getHeader());
                    dataSourceField.setValidOperators(
                            OperatorId.GREATER_OR_EQUAL,
                            OperatorId.LESS_OR_EQUAL,
                            OperatorId.IBETWEEN_INCLUSIVE);
                } else {
                    dataSourceField = new DataSourceField(
                            column.getAttribute(),
                            FieldType.ANY,
                            column.getHeader());
                    dataSourceField.setValidOperators(OperatorId.REGEXP);
                }
                dataSourceFields[i++] = dataSourceField;
            }
    
            ds.setFields(dataSourceFields);
            return ds;
        }
    Settings related to filterEditor for table is as follows:
    Code:
    table.setDataSource(getClientDataSourceWithFields());
    table.setSaveLocally(true);
    table.setAllowFilterOperators(true);
    table.setDefaultFilterOperator(OperatorId.REGEXP);
    The column is set up as follows:

    Code:
    ListGridField field = new ListGridField(column.getAttribute(), column.getHeader());
    field.setType(ListGridFieldType.INTEGER);
    field.setAllowFilterOperators(true);
    field.setAlwaysShowOperatorIcon(true);
    field.setFilterOperator(OperatorId.LESS_OR_EQUAL);
    
    TextItem item = new TextItem();
    item.addKeyPressHandler(new KeyPressHandler() {
    
                        @Override
                        public void onKeyPress(KeyPressEvent event) {
                            if (event.getKeyName().toLowerCase().equals("enter")) {
                                assembleQuestionAndGetResults(true);
                                logStatistics("grid", StatisticsType.ENTER_PRESS);
                            }
                        }
                    });
    item.setHoverWidth(300);
    item.setItemHoverFormatter(new FormItemHoverFormatter() {
    
                            @Override
                            public String getHoverHTML(FormItem item, DynamicForm form) {
                                String html =
                                        "<b>Less than or equal to</b><br>"
                                        + "Search for numbers less than or equal to the given number.<br>"
                                        + "<i>Example: '500'</i><br>"
                                        + "will search for those less than or equal to 500.<br>"
                                        + "<br>"
                                        + "<b>Greater than or equal to</b><br>"
                                        + "Search for numbers greater than or equal to the given number.<br>"
                                        + "<i>Example: '500'</i><br>"
                                        + "will search for those greater than or equal to 500.<br>"
                                        + "<br>"
                                        + "<b>Between (inclusive)</b><br>"
                                        + "Search for numbers between two numbers.<br>"
                                        + "<i>Example: '100...1000'</i><br>"
                                        + "will search between 100 and 1000, including 100 and 1000.";
                                return html;
                            }
                        });
    field.setFilterEditorProperties(item);
    I use smartGWT version 6.0p with GWT version 2.8.1
    Last edited by HenrikAlk; 13 Feb 2018, 04:55.

    #2
    We're not sure what you're reporting here - you show some code that seems to just crash while trying to log some criteria. This odd error looks like it could be corrupt criteria, or you might be doing something like using mismatched versions of SmartGWT and the underlying SmartClient libraries. There's not enough information here for us to look into a possible problem.

    Separately you say your grid won't accept IBETWEEN_INCLUSIVE criteria, but you don't show code that would reproduce that. If there were such a bug, it would be trivial to reproduce by adding just a few lines to a sample, but we already know that won't work to reproduce the problem, since we have such automated tests. All we can offer here is: your code is partial, but you don't seem to be enabling allowFilterExpressions in the code you've shown, and that's required for IBETWEEN_INCLUSIVE to be editable in the FilterEditor.

    Let us know if you can find evidence of a framework issue, and can make it reproducible for others. Also please remember to put your full version, and to test against the latest patched version before reporting issues.

    Comment


      #3
      We had forgotten to update the GIT branch we are working in to the latest SmartGWT. Our apologies. Now it works as intended!
      If anyone are looking for how to programmatically set the Filter Editor Criteria for a Criteria that has Operator = IBETWEEN_INCLUSIVE, use Criterion.setAttribute("start", yourStartValue) and Criterion.setAttribute("end", yourEndValue) instead of supplying the value in the Criterion(String fieldName, OperatorId operator, String value) constructor. I.e, do as follows:

      Code:
      AdvancedCriteria advancedCriteria = new AdvancedCriteria();
      
      Criterion criterion = new Criterion(yourFieldName, OperatorId.IBETWEEN_INCLUSIVE);
      criterion.setAttribute("start", yourStartValue);
      criterion.setAttribute("end", yourEndValue);
      advancedCriteria.addCriteria(criterion);
      
      yourListGrid.setFilterEditorCriteria(advancedCriteria);
      Remember to set yourListGrid.allowFilterExpressions(true); to allow this kind of filter operator.

      Comment


        #4
        Hi HenrikAlk,

        there are also overloads of the constructor with 4 params instead of 3, for start+end.

        Best regards
        Blama

        Comment

        Working...
        X