Sorting and filtering the data
We got the data and we used templates to display it and bind it to the WinJS
control. Now, what if we need to sort the data items or even filter out unwanted items based on a certain criterion? The binding list API provided by the WinJS
library handles this seamlessly using built-in methods such as createSorted
and createFiltered
. If we go back to the code we wrote earlier to fetch the tweets and write the bindingList
variable we created, which is an instance of WinJS.Binding.List
, and try to call the method createSorted
, you will notice the autocomplete feature lists the other two built-in functions provided for this functionality, as shown in the following screenshot:
These two methods will create a view over its data called "sorted projection". The createSorted
method will return a SortedListProjection
object, which represents a sorted view over the data it holds, and similarly the createFiltered
method will return a FilteredListProjection
object representing...