Announcement

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

    Filter on multiselect values in listgrid

    Version: v11.0p_2017-05-26/PowerEdition Deployment (built 2017-05-26)
    I have a listgrid in which a column is of type multiselect. Now i want to show a filter such that a dropdown with values is displayed. Whenever user selects, any value(s), all the records which contain any of the values in filter should be displayed.

    How can i achieve this. I have written below code till now
    public static void setFilterForAttrValues(IListGridField attrField) {
    SelectItem filterSelectItem = new SelectItem();
    final DataSource materialAttrDataSource = DataSource.get(ClientConstants.MATERIAL_ATTR_DS);
    filterSelectItem.setDisplayField(MATERIAL_ATTR_DS_PRINT_CODE);
    filterSelectItem.setValueField(MATERIAL_ATTR_DS_PRINT_CODE);
    filterSelectItem.setOptionDataSource(materialAttrDataSource);
    filterSelectItem.setMultiple(true);
    filterSelectItem.setAutoFetchData(true);
    attrField.setFilterEditorProperties(filterSelectItem);
    }

    But this is not working properly. If i enter A in filter and a records contains A,B it is not displayed. But records containing only A are displayed.

    Please help.

    #2
    Look in the Developer Console, RPC tab, at what operator is being applied to the criteria - if it isn't "inSet", you can call attrField.setFilterOperator(OperatorId.IN_SET).

    If it *is* "inSet", we'll need to see a standalone runnable sample, including the DS definition, which can be marked clientOnly.

    Comment


      #3
      Hi,

      there is no FieldType.MULTISELECT.
      Assuming your data is ", A, B, N, Z, " and you want to filter, you might try this on your SelectItem in the filterRow:
      Code:
      setMultiple(true);
              setCriterionGetter(new FormItemCriterionGetter() {
                  @Override
                  public Criterion getCriterion(DynamicForm form, FormItem item, TextMatchStyle textMatchStyle) {
                      return this.getCriterion(form, item);
                  }
      
                  @Override
                  public Criterion getCriterion(DynamicForm form, FormItem item) {
                      SelectItem si = (SelectItem) item;
                      if (si.getSelectedRecords() != null && si.getSelectedRecords().length > 0) {
                          AdvancedCriteria finalOrCrit = new AdvancedCriteria(OperatorId.OR);
                          for (int i = 0; i < si.getSelectedRecords().length; i++) {
                              String productId = si.getSelectedRecords()[i].getAttributeAsString(DatasourceFieldEnum.T_PRODUCT__ID.getValue());
                              productId = ", " + productId + ",";
                              finalOrCrit.appendToCriterionList(
                                      new Criterion("FIELDNAME", OperatorId.CONTAINS, productId));
                          }
                          return finalOrCrit;
                      } else
                          return null;
                  }
              });
      Check with your data regarding the leading and trailing commas.
      Otherwise, post the currently generated criteria and the expected criteria from the Developer Console (either RPC Tab or changed normal output with a logging category).

      Generally, if you meant multiple="true" as field attribute in your .ds.xml, it is generally worth thinking about normalizing, because thats almost always the right thing to do in a OLTP Application.

      Best regards
      Blama

      Comment


        #4
        Thanks Blama.
        The field value is a string array. The criteria is created like below.

        {
        "operator":"or",
        "_constructor":"AdvancedCriteria",
        "criteria":[
        {
        "fieldName":"fieldname",
        "operator":"contains",
        "value":"STLJ"
        },
        {
        "fieldName":"fieldname",
        "operator":"contains",
        "value":"STBJ"
        }
        ]
        }

        1. The values are not filtered.
        2. If i select only one value it is not getting displayed after i close the filter item.

        Comment


          #5
          Ok, if it is an array, I'd first try the solution from Isomorphic in #2.
          For the 2nd problem I have no idea at the moment. You should be able to easily create a testcase, as this is only one FormItem+DS.

          Best regards
          Blama

          Comment


            #6
            Thanks Blama.
            I am trying to create a testcase.
            I dont think using IN_SET will work in my case because, the field values may contain multiple values say A,B,C. If we apply filter on A,B then i want the field to show up on filter.
            But the filter applied would be A,B,C in set A,B. This is false.
            Please correct me if i am wrong.

            Comment


              #7
              Try it. If it is the way you say, create a setCriterionGetter(new FormItemCriterionGetter()...) like in #2, but with different logic, to build
              Code:
              {
              "operator":"or", 
              "_constructor":"AdvancedCriteria", 
              "criteria":[
              {
              "fieldName":"fieldname", 
              "operator":"inSet", 
              "value":"A"
              }, 
              {
              "fieldName":"fieldname", 
              "operator":"inSet", 
              "value":"B"
              },
              {
              "fieldName":"fieldname", 
              "operator":"inSet", 
              "value":"C"
              },
              ....
              ]
              }
              For the other issue, try building the testcase for Isomorphic.

              Best regards
              Blama

              Comment


                #8
                I created the criteria like this.

                {
                "operator":"or",
                "_constructor":"AdvancedCriteria",
                "criteria":[
                {
                "fieldName":"attr4PrintCodes",
                "operator":"inSet",
                "value":"STBJ"
                },
                {
                "fieldName":"attr4PrintCodes",
                "operator":"inSet",
                "value":"STFH"
                }
                ]
                }

                But now if the field contains array of {"STFH","STBJ","LMNP"} it will not be displayed. If it contains only "STFH" or "STBJ" it is displayed.

                Comment


                  #9
                  Hi,

                  then you should build a testcase for this, because I'd expect to see the record as well. Should be simple, perhaps do it in JavaScript online in this sample. Add a primaryKey, a multiple field, the filterField, edit some data, try to filter. Might be faster than in SmartGWT.

                  Best regards
                  Blama

                  Comment

                  Working...
                  X