Dynamically Sort a Repeater
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.