primefaces: DataTable: clearFilters doesnt work for complex input widgets like p:selectOneMenu

Describe the defect When using p:selectOneMenu in DataTable as custom filter, a call to DataTable#clearFilters() resets the filter of the DataTable but not the displayed value of the p:selectOneMenu. It works as expected when using h:selectOneMenu instead.

Reproducer See primefaces-test.zip.

Environment:

  • PF Version: 11.0.0-RC2
  • JSF + version: Mojarra 2.3.14.payara-p2
  • Affected browsers: ALL

To Reproduce Steps to reproduce the behavior:

  1. Start the reproducer.
  2. Select ‘true’ in column c1
  3. Select ‘true’ in column c2
  4. Click the filter reset button.
  5. Filter for DataTable is reset, value of c1 filter is reset, but value of c2 filter is still ‘true’.

Expected behavior Value of custom filter with p:selectOneMenu should be reset too when calling DataTable#clearFilters().

Referenced issues #6669, #6670

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 27 (27 by maintainers)

Commits related to this issue

Most upvoted comments

we could also do something like:

this.thead.find('> tr > th.ui-filter-column > .ui-column-customfilter :input').val(''); // old function for basic inputs
this.thead.find('> tr > th.ui-filter-column > .ui-column-customfilter').each(function() { // new function for resetting widgets
    var widgetElements = $(this).find('.ui-widget');
    widgetElements.each(function() {
        var widget = PrimeFaces.getWidgetById(this.attr('id'));
        if (widget && typeof widget.resetValue === 'function') {
            widget.resetValue(false);
        }
    });
});

and each input widget can add:

resetValue: function(triggerChangeEvent) {
}

so even a user can use it to reset + trigger events

i would do it like:

        this.thead.find('> tr > th.ui-filter-column > .ui-column-customfilter').each(function(idx) {
            var widgetElement = $(this).find('.ui-widget');
            if (widgetElement.length > 0) {
                var widget = PrimeFaces.getWidgetById(widgetElement .attr('id'));
                if (widget && typeof widget.resetValue === 'function') {
                    widget.resetValue(false);
                }
            }
            else {
                $(this).find(':input').val('');
            }
        });

Oh slick! Then we could check InstanceOf widget SelectOne and call its seletcValue or selectManyCheckbox like uncheckAll() wdget method etc!

in theory we can look for .ui-widget and check PF.getWidgetById