Announcement

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

    ListGrid Clear Filter Event Handler

    Version: v12.1p_2021-07-21/Enterprise Deployment
    Browser: Chrome(latest)

    Is there currently a way to intercept an event from when a user clicks the 'Clear Filter' MenuItem from the context menu of the filter button in the top right of a ListGrid? (Please see attached image). Additionally, is there currently a way to programmatically set a column's filter type? We have attempted to use setFilterOperator method for the columns respective ListGridField, but it did not seem to take affect after the grid has loaded. The following showcase can be used to look at these functionalities: https://www.smartclient.com/smartgwt...tfilter_filter

    Our end goal with this request is to set the filter operators back to default after a user uses the clear filter button in the grid.

    Thank you for your time.
    Attached Files

    #2
    You could use the CriteriaChanged handler:

    https://www.smartclient.com/smartgwt...hangedHandler-

    Although, if what you really want is to allow users to go back to the original criteria, we would recommend either:

    1. having your own menu item or button for that, so Clear Filter still works

    OR

    2. specifying your criteria as listGrid.implicitCriteria, so they can never be edited or cleared

    As far as changing the operator, if you apply criteria and they are editable by the FilterEditor, you should find that the operator just switches. But you can also change listGridField.operator via setFieldProperties() - this is in the underlying docs but got munged by JavaDoc, we'll fix that.

    Comment


      #3
      We were able to use a separate button to reset the filter operators per field using your advice. However, using the CriteriaChanged handler did not work for us to get the clear button assigned to the ListGrid's filter editor to work. The clear button in question was attached in the screenshot in case I described it incorrectly.

      For reference, we had our grid's class use the com.smartgwt.client.widgets.form.events.HasCriteriaChangedHandlers interface, and added the following override method:

      @Override
      public HandlerRegistration addCriteriaChangedHandler(CriteriaChangedHandler handler)
      {
      return addHandler(handler, com.smartgwt.client.widgets.form.events.CriteriaChangedDevent.getType());
      }

      Then we tried using this with:

      addCriteriaChangedHandler(event -> {
      // Custom Clear
      });

      When debugging this it appeared that the event handler was never reached. Do you have any recommendations for us to get this to work?
      Attached Files

      Comment


        #4
        We were referring to this 13.0+ API. There's actually no CriteriaChanged handler for grids in 12.1 - the one you've tried to use is for forms.

        So, you'll need to do this another way - for example, you could detect null criteria in a FilterEditorSubmitHandler, like this:

        Code:
        grid.addFilterEditorSubmitHandler(new FilterEditorSubmitHandler() {
            @Override
            public void onFilterEditorSubmit(FilterEditorSubmitEvent event) {
                if (event.getCriteria() == null) {
                    // "Clear Filter" was just clicked (or the filter was cleared in some other way)
                }
                ...
            }
        });

        Comment

        Working...
        X