filter data using dropdown?

前端 未结 1 1184
庸人自扰
庸人自扰 2020-12-09 20:08

I have an array of objects which are just items. I also have a dropdown which I would like to use to allow the user to filter by price or rating however on page load there s

相关标签:
1条回答
  • 2020-12-09 20:48

    First and foremost, your select values are ambiguous. They contain values that can filter AND sort the entries - Separate the two since they are two different functionality.

    Next, you need to define a custom Filter which will filter the data based on the rating selected. For this, you enhance the filtering criteria with the "Rating" property to associate the rating selected with a rating value.

    Finally, associate the sorting with a predicate and a reverse value - the predicate determines the property / column to determine for the sort (price in your case) while the reverse determines the ascending / descending nature of the sort.

    The entire code can be found here - http://plnkr.co/edit/n7TebC?p=preview

    I have updated the plunkr and introduced comments so let me know if you do not understand a code.

    0 讨论(0)
提交回复
热议问题