Categories
BLOG

torvix pipe order

Torvix pipe order

Angular 5+ Order Pipe

Order your collection by a field

or see code example

For Angular lower than 5 use version 1.1.3

In case you’re using systemjs – see configuration here. Otherwise skip this part.

In HTML template

Param Type Default Value Details
collection array or object The collection or object to sort
expression string or string array The key or collection of keys to determinate order
reverse (optional) boolean false Reverse sorting order
caseInsensitive (optional) boolean false Case insensitive compare for sorting
comparator (optional) Function Custom comparator function to determine order of value pairs. Example: (a, b) => < return a >b ? 1 : -1; > See how to use comparator

Import OrderModule to your module

And use pipe in your component

Use dot separated path for deep properties when passing object.

Use OrderPipe in the component

Import OrderPipe to your component:

Add OrderPipe to the constructor of your component and you’re ready to use it:

Case insensitive / Case sensitive

Case insensitive flag is the third parameter passed to the pipe. Can be true to make comparison case insensitive and false to make comparison case sensitive. By default value is set to false.

  • Make case insensitive order (Third parameter is true )

  • Switching third parameter to false will do case sensitive comparison to order collection:

If this project help you reduce time to develop, you can give me a cup of tea 🙂

Angular order pipe, order collection by a field ]]>