Search code examples
filtersapui5visibletypeerror

SAPUI5 - FilterBar - setVisible not working


I'm using sap.ui.comp.filterbar.FilterBar Control on a project. Everything works fine, except when I try to hide this Control.

var oFilterBar = new sap.ui.comp.filterbar.FilterBar("filterBar",{
    reset: oController.handleOnReset,
    search: oController.handleOnSearch,
    showRestoreOnFB: true,
    showClearOnFB: true,
    showRestoreButton: true,
    showClearButton: true,
    ...
    });
oFilterBar.setVisible(false);

I'm getting the following error:
Uncaught TypeError: oFilterBar.setVisible is not a function

Since this property is being inherited from sap.ui.core.Control class, this should work and I think it has nothing to do with versions either (I'm using 1.24).


Solution

  • It has something to do with the version.

    In SAPUI5 1.28[1] the property visible was moved to sap.ui.core.Control so any Control extending it would have this property as well.

    If you are using an earlier version only Control that implement this property themselves can be made invisible.


    You could however extend the control you are using to include this property:

    sap.ui.comp.filterbar.FilterBar.extend("my.FilterBar", {
        metadata: {
            properties: {
                visible: {
                    type: "boolean",
                    group: "Appearance"
                }
            }
        },
        renderer: function (oRm, oControl) {
            if (oControl.getVisible()) {
                sap.ui.comp.filterbar.FilterBarRenderer.render(oRm, oControl);
            } else {
                // Handle invisibility
            }
        }
    });