# Length of Filtered List via Javascript

**URL:** <https://community.weweb.io/t/length-of-filtered-list-via-javascript/3534>\
**Category:** Ask us anything\
**Created:** [July 15, 2023, 2:16am UTC](https://community.weweb.io/t/length-of-filtered-list-via-javascript/3534 "2023-07-15T02:16:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![RCS](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@RCS](https://community.weweb.io/u/RCS)\
**Post date:** [July 15, 2023, 2:16am UTC](https://community.weweb.io/t/length-of-filtered-list-via-javascript/3534/1 "2023-07-15T02:16:19Z")

</div>

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.

 ![Screenshot 2023-07-14 at 7.11.52 PM](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/d/d904da84031130f3e3da8dc1c05e3d107c1b6445.png)  
 ![Screenshot 2023-07-14 at 7.11.37 PM](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/f/ff6ed66794d8f0be7866e21fb7e06857d1313341.png)

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?

---

<div class="post-metadata">

**Author:** ![Alexis](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/alexis/32/13248_2.png) [@Alexis](https://community.weweb.io/u/Alexis)\
**Post date:** [July 17, 2023, 2:40pm UTC](https://community.weweb.io/t/length-of-filtered-list-via-javascript/3534/2 "2023-07-17T14:40:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RCS](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@RCS](https://community.weweb.io/u/RCS)\
**Post date:** [July 17, 2023, 4:05pm UTC](https://community.weweb.io/t/length-of-filtered-list-via-javascript/3534/3 "2023-07-17T16:05:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Alexis](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/alexis/32/13248_2.png) [@Alexis](https://community.weweb.io/u/Alexis)\
**Post date:** [July 17, 2023, 4:18pm UTC](https://community.weweb.io/t/length-of-filtered-list-via-javascript/3534/4 "2023-07-17T16:18:41Z")

</div>

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.

 ![Capture d’écran 2023-07-17 à 18.16.44](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/d/dcff97605ab453ee72b5d137ae1c238c33097294.png)

---

<div class="post-metadata">

**Author:** ![RCS](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@RCS](https://community.weweb.io/u/RCS)\
**Post date:** [July 17, 2023, 6:22pm UTC](https://community.weweb.io/t/length-of-filtered-list-via-javascript/3534/5 "2023-07-17T18:22:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RCS](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@RCS](https://community.weweb.io/u/RCS)\
**Post date:** [July 17, 2023, 7:54pm UTC](https://community.weweb.io/t/length-of-filtered-list-via-javascript/3534/6 "2023-07-17T19:54:18Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/2/2ef09d7320857bb7fbd19678d5ca365004961dd6.png)

Calling the formula does not pull the filtered list.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/d/d028fd24f6f46ea0a29615c74e55598454d5de4f.png)

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

---

<div class="post-metadata">

**Author:** ![Alexis](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/alexis/32/13248_2.png) [@Alexis](https://community.weweb.io/u/Alexis)\
**Post date:** [July 18, 2023, 9:48am UTC](https://community.weweb.io/t/length-of-filtered-list-via-javascript/3534/7 "2023-07-18T09:48:55Z")

</div>

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](http://support.weweb.io)
