Search code examples
javascriptsapui5sap-fiori

SAPUI5 How to connect the filters of two Smart tables


I have two smart tables, both having a personalization button where the user can add a filter. Now I need to connect the tables, that a filter applied to one table is also applied for the other table.

What I achieved already: If the user applies a filter to one table, I can use the beforeRebindTable event to see it with the help of evt.getParameter("bindingParams").filters. Afterwards I can copy the variant applied to the table to the other table

var oVariantWithFilters = this.getView().byId("SmartTableOne")._oCurrentVariant

this.getView().byId("SmartTableTwo")._oCurrentVariant = oVariantWithFilters 

As a result both are filtered correctly.

BUT: If the user opens the other smart tables personalization (in this case the one of SmartTableTwo) he won't see the filter that is applied and is also not able to remove it at this place.

So the question is about how to also add the filter information in the personalization dialog of the other table. (Copying the full _oPersController is not possible as this not only controlls the filters.. also which columns are shown ...)

I hope this is understandable.

Best regards, Christian R


Solution

  • Easier than expected...

    var oVariantWithFilters = this.getView().byId("SmartTableOne").fetchVariant()
    
    this.getView().byId("SmartTableTwo").applyVariant(oVariantWithFilters) = oVariantWithFilters
    

    By using the applyVariant function not copying the variant... the personalisation dialog is also created .. so this solves my issue. :)