Announcement

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

    Filter emtpy values in select item in listgrid

    Hi Team,

    I am using SmartClient Version: v11.1p_2017-07-24/PowerEdition Deployment (built 2017-07-24)

    I have a select item filter on listgrid with setMultiple(true). Now some fields contain empty value. But when i select only the empty value in filter the filter gets cleared. Is there any way i can filter out blank values in select item.

    #2
    If we understand the question, you want the user to be able to ask to see records which are *either* blank or have some specific value, correct?

    This is easy for an end user to achieve if you give them a FilterBuilder as the editing interface.

    Alternatively you could add an extra data value to the valueMap for the SelectItem, with a display value like "[Blank]" and some internal data value (like "blank_chosen"). Then you can use setCriterionGetter() to provide a function so that, if this data value is chosen, the criteria you return actually adds an isBlank criterion instead of the usual OR of all chosen values.

    Comment


      #3
      Thanks Isomorphic ...It works!

      Comment


        #4
        Hi
        To filter out null values, i changed all null values to space and the filtering worked. But now i need to edit these, and cannot save space in case of null.
        I am trying to set "EMPTY" value in filter dropdown and whenever the user selects this, i want to replace "EMPTY" with OperatorId.IS_NULL.

        filterItem.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("field_name");
        if(productId.equals("Filter Blank")){
        finalOrCrit.appendToCriterionList(
        new Criterion("field_name", OperatorId.IS_NULL, "isNull"));
        }else{
        finalOrCrit.appendToCriterionList(
        new Criterion("field_name", OperatorId.CONTAINS, productId));
        }
        }
        return finalOrCrit;
        } else
        return null;
        }
        });

        However, in logs i get an error this.pickList is undefined.
        Is this the correct way of doing it.

        Comment


          #5
          Most likely not the root cause, but your IS_NULL should read: new Criterion("field_name", OperatorId.IS_NULL).

          Best regards
          Blama

          Comment


            #6
            Trying out your code (with Blama's correction) doesn't immediately lead to the claimed error. The problem is most likely coming from code or settings you haven't shared.

            Please show complete code that reproduces the problem, tested against the latest patched version.

            Also: please remember to always show the stack trace for any JavaScript error. Instructions, and one of many reminders to always do this, can be found in the Debugging topic.

            Comment


              #7
              As mentioned above, I want to add an extra data value to the valueMap for the SelectItem, with a display value like "[Blank]" and some internal data value (like ""). Then whenever blank is selected i want to override the criteria and replace the "[Blank]" in crieria with OperatorId.IS_BLANK.
              If we use setCriterionGetter() to provide a function we need to override two methods - public Criterion getCriterion(DynamicForm form, FormItem item, TextMatchStyle textMatchStyle) and public Criterion getCriterion(DynamicForm form, FormItem item) . When i do this it gets called recursively. Can you please help me with the correct way of setting the new criteria.

              Comment


                #8
                What do you mean “it gets called recursively”? That should only happen if you created infinite recursion yourself. If you think the framework is doing this, show a stack trace of the tail end of the recursion that actually involves framework methods, not just your own code.

                Comment

                Working...
                X