# How to filter repeater output using code

**URL:** <https://forum.wixstudio.com/t/how-to-filter-repeater-output-using-code/37074>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [July 22, 2021, 1:52pm UTC](https://forum.wixstudio.com/t/how-to-filter-repeater-output-using-code/37074 "2021-07-22T13:52:00Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![paulgoodchild](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/paulgoodchild/32/7087_2.png) [@paulgoodchild](https://forum.wixstudio.com/u/paulgoodchild)\
**Post date:** [July 29, 2021, 8:08am UTC](https://forum.wixstudio.com/t/how-to-filter-repeater-output-using-code/37074/21 "2021-07-29T08:08:53Z")

</div>

Thanks for all of the great comments and helpful examples from everyone on this post - really great to see that a forum is so useful and that the people on there seem to care about the users and the questions asked! Top marks.

So, I’ve done something stupid and deleted a vital part of my code which now means that what was working, is no longer, and I cannot seem to sort out what I need to put back in order for things to operate correctly! We’ve all done it I’m sure, but I’ve completely forgotten what I had in place to make this work!

I took advice from Giro here and originally was taking a copy of the LocalBusinesses collection data, which I then worked on in order to test the postcodes and eventually come up with another copy of the data (filtered) which I then assigned to the repeater and which was displayed on screen.

Everything was working, but now it’s not as I’ve done something and cannot find out what’s wrong - experience lacking again, sorry!

Could someone please show me the variable assignment and then the code that will allow me to copy the collection data into an array or object (still not sure about the difference on these yet!), so that I can then use this to test the postcodes and to eventually filter this and assign the now filtered array/object to show in the repeater. I am struggling with variable setup/assignment types and what’s needed to copy data from a collection into a variable. Also, how to assign the new displayArray to the repeater as this variable assignment is now incorrect too.  
**Wish I’d never deleted the code!!!**  
**Or, wish I had better memory!!!**

This is the logic of my code right now if this helps;

Make copy of the collection data, creating (origArray).  
Call GoogleMaps API to obtain all distances between origArray postcodes and user postcode, creating (postcodeArray).  
Test each distance and filter into new array for display with new \_ids (displayArray).  
Assign displayArray to the repeater in order to display on screen.

Thanks for any help with the above.

---

<div class="post-metadata">

**Author:** ![giri-zano](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/giri-zano/32/80469_2.png) [@giri-zano](https://forum.wixstudio.com/u/giri-zano)\
**Post date:** [July 29, 2021, 8:13pm UTC](https://forum.wixstudio.com/t/how-to-filter-repeater-output-using-code/37074/22 "2021-07-29T20:13:56Z")

</div>

@paulgoodchild Don’t you have a backup? Wix makes site backups automatically when autoSave is turned on and if you press Save. It’s in the Site|Site History menu from the top. Take a guess, restore one and have a look at the code.

---

<div class="post-metadata">

**Author:** ![paulgoodchild](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/paulgoodchild/32/7087_2.png) [@paulgoodchild](https://forum.wixstudio.com/u/paulgoodchild)\
**Post date:** [August 1, 2021, 6:46pm UTC](https://forum.wixstudio.com/t/how-to-filter-repeater-output-using-code/37074/23 "2021-08-01T18:46:07Z")

</div>

So, after many days of frustration, learning and help from some greats guys and girls on this forum, I have finally managed to come up with some (newbie) code that actually works - so I thought I’d share it for others so that someone may find it useful…

My requirement was as follows;

Hold a database of businesses in a collection, including a UK postcode of their location.  
Have a website page be able to display “local” businesses for the user based on their own postcode and a search radius, by looking at the businesses postcodes and then displaying the filtered results in the page repeater.

This proved pretty tricky for a newbie Javascript/Wix coder like me, but I got there in the end with the following process;

1. Do a wixData.query on the collection and save the results into a new array.
2. Create the API call to Google Maps in order to look up distances between the users postcode and all of the business postcodes in the saved array/collection.
3. Loop through all of the businesses in the array/collection, and if the postcode distance is within the radius entered by the user, push the business data to a new array which will be used for display.
4. Assign the new display array to the page repeater.

There are some intricacies within the code in order to carry out the above steps, but these are the basics listed above.

Google Maps API code and main page code is listed below - hope someone finds all or part of it useful for future projects. I’ve learnt a hell of a lot along the way and hopefully now, I’ll continue - thanks to all who helped out here!

* * *

---

<div class="post-metadata">

**Author:** ![vendor](https://avatars.discourse-cdn.com/v4/letter/v/f08c70/32.png) [@vendor](https://forum.wixstudio.com/u/vendor)\
**Post date:** [November 29, 2022, 7:31pm UTC](https://forum.wixstudio.com/t/how-to-filter-repeater-output-using-code/37074/24 "2022-11-29T19:31:46Z")

</div>

@paulmgoodchild - did you ever recover your code for this? I have to do something similar and would love to have some starter code to get started. Thank you.

---

<div class="post-metadata">

**Author:** ![christina54251](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/christina54251/32/35238_2.png) [@christina54251](https://forum.wixstudio.com/u/christina54251)\
**Post date:** [January 28, 2023, 11:01pm UTC](https://forum.wixstudio.com/t/how-to-filter-repeater-output-using-code/37074/25 "2023-01-28T23:01:33Z")

</div>

@paulgoodchild@paulmgoodchild That’s so awesome you figured this out. I am hoping to do something similar. Could you please share the successful code?

Thanks so much!

[Previous page](https://forum.wixstudio.com/t/how-to-filter-repeater-output-using-code/37074.md?page=1)
