Length of Filtered List via Javascript

I have a collection list with several advanced filters. I want to show text like ‘no results for the filters selected’. I know there isn’t a native solution in Weweb. I also know a backend solution or filtering at the collection level are options. However, with so many filters, I really prefer to just do it at this level.

I am trying to solve it with some JS and have used this code to get the html id of the collection list, and figure out how many children it has.


This has gotten me a little progress, but I am having 2 major problems:

First: when the collection list has no items, it still shows as having 1 child. So a filtered list with 0 and 1 both return 1 item. making it unable to distinguish when there are 0 items.

Second: the value updates in the javascript code, but the condition does NOT update as I filter the list. In other words, if I bind the display to if that JS code is less than 2. It won’t update despite the list being smaller than 2.

An API call or variable change on each filter would be way too laborious for me. I also really enjoyed the live filtering per each filter and don’t want to turn it into ‘choose all filters then apply’.

Any ideas?

Hi, you can create a custom formula with your filters. Then reuse this formula to display conditionally your collection list or your message.

Again, I stated that I have ~10+ filters and a formula for all of them would be complicated to maintain and so I am looking to see if I can create a simpler method.

What do you mean ? How it would be different ?

You can put your filters inside the formula so you can reuse the formula everywhere you need the filtered collection, it will be easier yo maintain and you will be able to build condition on top, using the formula Length for example.

oh I wasn’t aware of this feature of re-usable formulas! Let me try this out.

This solution doesn’t work. applying the length() over the reusable formula that has the filters applied doesn’t pull the filtered length. It pulls the unfiltered length.

For example:

This should have a length of 2

Calling the formula does not pull the filtered list.

It appears the filters are not applied on the re-usable formulas. Is this a bug?

Oh yes, you’re right, we already have a bug opened on it. Should be fixed this week! If you want to follow the advancement of the ticket you can open one on support.weweb.io

1 Like