Sorting Items in a ListView Control

You can sort the items displayed with a ListView control by sorting the items in the ListView control’s data source. For example, you might want to sort a list of products in order of the product name or price (see Figure 8.11).

Image

FIGURE 8.11 Sorting ListView items

The WinJS.Binding.List object supports the createSorted() method. This method accepts a sort function that returns a new WinJS.Binding.List sorted according to the function.

For example, the following code sorts a list of products in order of the product name:

// Create a List of productsvar listProducts = new WinJS.Binding.List([ ...

Get Windows® 8.1 Apps with HTML5 and JavaScript Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.