ATTENTION: THIS IS OUR OLD SITE. TO SEE OUR NEW WEBSITE, CLICK HERE.
Allow users to dynamically sort repeater data in ascending or descending order using a checkbox.
You can dynamically sort repeater data in ascending or descending order based on any field available in your collection. This example will show you how to sort the code bank data repeater on the WixCodeBank home page by the number of views using a checkbox. If not checked, then our code bank data is sorted by a predefined priority field. See 'Views Counter for Dynamic Pages' on how to count and save dynamic page views to your collection.
The first step is to add a checkbox (or whatever user input field you'd like) to toggle the new sort. An onChange event listener is added to the checkbox (called iptMostViewed_click in this example). Thereafter, add the following sort code to the checkbox.
Please login or sign-up (it's free!) to view our code. Refresh the page if already logged in.
Disclaimer: To the best of our knowledge, this code works for its stipulated purpose. If you find an error in our code, or know of a better way to achieve the same result - please contact us! We will help where we can, however please be aware that the code is provided 'as is' and without a promise of support in using or implementing it.