Search code examples
sapui5

Remove Filter Option from SmartTable


We have implemented a SmartTable and everything is working fine. I would like to remove only the Filter option provided by SmartTable useTablePersonalisation option.

Is this Possible ?

Regards, Mayank


Solution

  • You can remove the filter (and all other options) from the SmartTable's embedded P13nDialog via customData as shown in this SAPUI5 Explored Sample: P13nDialog with disabled 'Filter' tab - Variation.

    SmartTableWithoutFilterOption.view.xml

    <core:View xmlns:core="sap.ui.core" xmlns="sap.ui.comp.smarttable"
        xmlns:html="http://www.w3.org/1999/xhtml"
        xmlns:customData="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1"
        controllerName="my.namespace.SmartTableWithoutFilterOption">
    
        <SmartTable
            tableType="ResponsiveTable" header="A bunch of data"
            enableAutoBinding="true" entitySet="RecordSet"
            customData:p13nDialogSettings='{filter:{visible:false}}' />
    </core:View>
    

    Please note that you need to declare the xmlns:customData namespace for the customData:p13nDialogSettings property to work.

    But you can also use the longer customData aggregation notation.

    SmartTableWithoutFilterOptionLongNotation.view.xml

    <core:View xmlns:core="sap.ui.core" xmlns="sap.ui.comp.smarttable"
        xmlns:html="http://www.w3.org/1999/xhtml"
        controllerName="my.namespace.SmartTableWithoutFilterOptionLongNotation">
    
        <SmartTable
            tableType="ResponsiveTable" header="A bunch of data"
            enableAutoBinding="true" entitySet="RecordSet">
            <customData>
                <core:CustomData
                    key="p13nDialogSettings"
                    value='\{
                        "filter": \{ "visible": false}
                    }' />
            </customData>
        </SmartTable>
    </core:View>
    

    To hide the other options use columns, sort or group instead of filter. You can also combine these settings to hide more than one option. The following code will only allow filtering.

    <core:CustomData
        key="p13nDialogSettings"
        value='\{
            "columns": \{ "visible": false},
            "sort": \{ "visible": false},
            "group": \{ "visible": false}
        }' />