Sorting Products
Learn to sort the products based on an attribute.
We'll cover the following...
We'll cover the following...
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