Sorting Products
Explore how to add sorting functionality to products in an Ember.js app integrated with Firebase. Learn to create sorting buttons and define actions in controllers to sort products by price on admin and category routes, enhancing data management within your application.
We can sort our products based on their price in the admin and category routes. We need to add the sorting buttons and sort the products in the controllers of these routes.
Adding sorting buttons
Let’s add ascending and descending sort buttons. We’ll also add a button to clear the sorting in our admin.hbs and category/index.hbs templates.
Adding buttons in the admin.hbs template
Open the app/templates/admin.hbs template and add the sort and clear buttons:
- Lines 31–36: We add a
divof4-coland three buttons.- Line 33: We add a button to sort the products in ascending order and attach a
sortascaction to it. - Line 34: We add a button to sort the products in descending order and attach a
sortdscaction to it.
- Line 33: We add a button to sort the products in ascending order and attach a