cancel
Showing results for 
Search instead for 
Did you mean: 

UI5: Dynamic filtering on ui.Table at load time

mandrew
Explorer
0 Kudos
743

I have a ui.Table that I want to filter by date, defaulting to six months in the past when the user opens the view.

Building the filter in javascript is easy enough, but I can't put the filter code in the view's init because the binding hasn't been created yet. Tying it to metadataLoaded isn't the right timing either. Is there a "bound" event somewhere that I'm missing in the documentation?

I tried putting the filter in the view XML, but I can't figure out how to put a dynamic date in the filter expression in the path, and the filter in XML doesn't support binding so I can't supply the "from" date that way.

So how can I filter the table using a dynamic date value without the user needing to trigger an event to cause it?

gichuhimd
Explorer
0 Kudos

Where is the date coming from?

mandrew
Explorer
0 Kudos

The date is built at run time - defaulting to 6 months previous to the current date.

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor
0 Kudos

https://blogs.sap.com/2021/03/23/ui5-tips-use-of-binding-suspend/

you can follow this blog, initially suspend the binding, once you set the filter, you can resume the binding

mandrew
Explorer
0 Kudos

Promising, but I still have the timing problem - code run through onInit runs before the binding specified in the XML is created, so I still can't get to the suspended binding to attach filters and resume it without a user-triggered event to do it.

junwu
Active Contributor
0 Kudos

how about adding the code in onafterrendering? it may help.

mandrew
Explorer
0 Kudos

That's the missing piece! Thank you!

Answers (0)