Announcement

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

    FilterBuilder and/or operands

    I'm using SmartGWT 3.0 eval.

    I have configured the type operators on the datasource I have bound to a FilterBuilder, e.g.:

    Code:
    mydatasource.setTypeOperators(FieldType.TEXT, myOperatorForStrings);
    FilterBuilder fb = new FilterBuilder();
    fb.setDataSource(mydatasource);
    and I find the and/or drop-down in the FilterBuilder only supplies the "and" option, no matter how many clauses are set. I'm not sure I'm describing this well; before I customized the type operators the FilterBuilder allowed the user to select "Match all" or "Match any" or "Match none" as the 'conjunction' between the filter clauses... I tried calling fb.setMatchAllTitle("All") but that didn't help.

    I can't find any API for controlling this aspect of the FilterBuilder. Thanks for any help.
    -Susan
    Last edited by susanpemble; 17 May 2012, 11:38.

    #2
    Looks like your list of valid operators for text fields did not include the "and" and "or" operators

    Comment


      #3
      I guess I wasn't clear; it's not the text operator that is missing, it's the ability to BUILD a complex filter -- to define more than one filter and specify whether to 'match all' of the filters, 'match any' of the filters, or 'match none' of the filters. Text operators configured for the datasource can't possibly also control the FilterBuilder's 'filter operators'. Do I have that wrong?
      Last edited by susanpemble; 21 May 2012, 06:35.

      Comment


        #4
        "Match All" is the Boolean "and" operator, and yes you can disable such operators if you use this API and omit them.

        Comment


          #5
          Since I'm not setting operators for Booleans I don't understand how I have disabled them.

          Code:
                FilterBuilder filterBuilder = new FilterBuilder();
          
                // Configure text operators using case-insensitive methods
                OperatorId[] operatorsForStrings = new OperatorId[] { 
                      OperatorId.IEQUALS, 
                      OperatorId.ICONTAINS,
                      OperatorId.ISTARTS_WITH, 
                      OperatorId.IENDS_WITH,
                      OperatorId.EQUALS_FIELD};
                logDataSource.setTypeOperators(FieldType.TEXT, operatorsForStrings);
          
                // Configure number operators
                OperatorId[] operatorsForNumbers = new OperatorId[] { 
                      OperatorId.GREATER_THAN, 
                      OperatorId.GREATER_OR_EQUAL,
                      OperatorId.GREATER_THAN_FIELD, 
                      OperatorId.BETWEEN, 
                      OperatorId.BETWEEN_INCLUSIVE, 
                      OperatorId.LESS_THAN,
                      OperatorId.LESS_OR_EQUAL, 
                      OperatorId.LESS_THAN_FIELD,
                      OperatorId.EQUALS,
                      OperatorId.EQUALS_FIELD};
                logDataSource.setTypeOperators(FieldType.FLOAT, operatorsForNumbers);
                logDataSource.setTypeOperators(FieldType.INTEGER, operatorsForNumbers);
                logDataSource.setTypeOperators(FieldType.TIME, operatorsForNumbers);
                logDataSource.setTypeOperators(FieldType.DATE, operatorsForNumbers);
                logDataSource.setTypeOperators(FieldType.DATETIME, operatorsForNumbers);
          
                filterBuilder.setDataSource(logDataSource);

          Comment


            #6
            What you're setting is all of the allowed operators for that field. You need to add the boolean operators or they won't be available for that field.

            Comment


              #7
              It's not a datasource FIELD that the Boolean operator is to be applied to.

              It seems that you aren't understanding the issue.

              The only thing I can think that you are trying to say is that I should specifically add operator types for Boolean fields on the datasource, even though that seems out of place:
              Code:
                    logDataSource.setTypeOperators(FieldType.BOOLEAN, new OperatorId[] { OperatorId.AND, OperatorId.AND } );
              This modification did not change the contents of the drop-down on the left side of the FilterBuilder widget. The drop-down still only provides the option to 'and' the filters that are specified.
              Last edited by susanpemble; 21 May 2012, 10:46.

              Comment


                #8
                Here's a screenshot - maybe that will be more clear.
                Attached Files

                Comment


                  #9
                  What happens if you include OperatorId.AND in your list of operators for Strings?

                  Code:
                        // Configure text operators using case-insensitive methods
                        OperatorId[] operatorsForStrings = new OperatorId[] { 
                              OperatorId.IEQUALS, 
                              OperatorId.ICONTAINS,
                              OperatorId.ISTARTS_WITH, 
                              OperatorId.IENDS_WITH,
                              OperatorId.EQUALS_FIELD,
                              OperatorId.AND};

                  Comment


                    #10
                    I tried that - no change.

                    UPDATE: you were right, I must have done something wrong when I tried that the first time.

                    So when Isomorphic said:
                    Originally posted by Isomorphic
                    ... and yes you can disable such operators if you use this API and omit them.
                    apparently what they meant is that if you use setTypeOperator() on the datasource that you bind to the FilterBuilder, you must always include the AND, OR and NOT operators in your operator array in order to maintain the default behavior of the FilterBuilder.
                    Last edited by susanpemble; 5 Jun 2012, 11:24.

                    Comment


                      #11
                      You need AND as well as OR (and NOT if you want that as well) in your lists of allowable operators for all types where you call setTypeOperators().

                      Comment


                        #12
                        I just re-tried your suggestion and this time got the results I was looking for - I must not have gotten a good refrresh last time.

                        By adding AND, OR and NOT to the operator set for FieldType.TEXT, the 'Match All', 'Match Any' and 'Match None' boolean operators are now restored to the Filter Builder.

                        Code:
                              // Configure text operators using case-insensitive methods
                              OperatorId[] operatorsForStrings = new OperatorId[] { 
                                    OperatorId.IEQUALS, 
                                    OperatorId.ICONTAINS,
                                    OperatorId.ISTARTS_WITH, 
                                    OperatorId.IENDS_WITH,
                                    OperatorId.EQUALS_FIELD,
                                    OperatorId.AND,
                                    OperatorId.OR,
                                    OperatorId.NOT };
                        Thanks for your suggestion Joe.

                        Comment

                        Working...
                        X