• Stars
    star
    243
  • Rank 166,088 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

β–Ό Angular 5+ orderBy pipe

Angular 5+ Order Pipe

downloads downloads downloads

Order your collection by a field

Demo page

https://vadimdez.github.io/ngx-order-pipe/

or see code example

https://stackblitz.com/edit/ngx-order-pipe

Install

npm install ngx-order-pipe --save

For Angular lower than 5 use version 1.1.3

Setup

In case you're using systemjs - see configuration here. Otherwise skip this part.

Usage

In HTML template
{{ collection | orderBy: expression : reverse : caseInsensitive : comparator }}

Arguments

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

import { NgModule } from '@angular/core';
import { BrowserModule  } from '@angular/platform-browser';
import { AppComponent } from './app';

import { OrderModule } from 'ngx-order-pipe';

@NgModule({
  imports: [BrowserModule, OrderModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})
export class AppModule {}

And use pipe in your component

import { Component } from '@angular/core';

@Component({
  selector: 'example',
  template: `
    <ul>
      <li *ngFor="let item of array | orderBy: order">
        {{ item.name }}
      </li>
    </ul> 
  `
})

export class AppComponent {
  array: any[] = [{ name: 'John'} , { name: 'Mary' }, { name: 'Adam' }];
  order: string = 'name';
}

Deep sorting

Use dot separated path for deep properties when passing object.

<div>{{ { prop: { list: [3, 2, 1] } } | orderBy: 'prop.list' | json }}</div>

Result:

<div>{ prop: { list: [1, 2, 3] } }</div>

Use OrderPipe in the component

Import OrderPipe to your component:

import { OrderPipe } from 'ngx-order-pipe';

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

constructor(private orderPipe: OrderPipe) {
  console.log(this.orderPipe.transform(this.array, this.order)); // both this.array and this.order are from above example AppComponent
}

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)
<li *ngFor="let item of array | orderBy: order : false : true">
  {{ item.name }}
</li>
  • Switching third parameter to false will do case sensitive comparison to order collection:
<li *ngFor="let item of array | orderBy: order : false : false">
  {{ item.name }}
</li>

Donation

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

paypal

License

MIT Β© Vadym Yatsyuk

More Repositories

1

ng2-pdf-viewer

πŸ“„ PDF Viewer Component for Angular
TypeScript
1,299
star
2

Counter-Strike-JS

Counter Strike implementation with Javascript/Typescript
TypeScript
269
star
3

ngx-filter-pipe

𝗩 Angular 5+ pipeline for array filtering.
TypeScript
146
star
4

ngx-img-fallback

πŸ–Ό Load placeholder image on image error, Angular 5+
TypeScript
82
star
5

ngx-online-status

πŸ”› Angular 5+ Detect online/offline state
TypeScript
22
star
6

roguelike-dungeon-crawler

react.js game
JavaScript
18
star
7

spr-viewer

Online sprite (*.spr) viewer
TypeScript
12
star
8

watchstocks

Track stocks
JavaScript
11
star
9

Who-wants-to-be-millionaire

Who wants to be millionaire game made with MEAN (MongoDB, Express, Angularjs, Nodejs)
JavaScript
11
star
10

backend-starter

Backend starter template project
JavaScript
6
star
11

frontend-starter

Angular based frontend starter
TypeScript
5
star
12

pinterest

Pinterest clone
JavaScript
4
star
13

pomodoro-app

Pomodoro time management app for OS X
Swift
4
star
14

football-quiz

Mobile quiz app
JavaScript
3
star
15

Google-Translate-Bar-App

Google translate in bar app for MacOS
Swift
3
star
16

weather-action

GitHub Action to print get and print weather
JavaScript
3
star
17

ngx-g2

G2 Component for Angular >= 2
TypeScript
3
star
18

qa

hackathon project
JavaScript
2
star
19

vd-create-app

JavaScript
2
star
20

ecast

FutureLab hackathon (2017) project
Swift
2
star
21

pomodoro

Pomodoro time management app
JavaScript
2
star
22

freelance

Web platform for freelance
PHP
2
star
23

automotive

My research/learning project
2
star
24

WebAssembly

JavaScript
2
star
25

create-backend-app

cli tool for createing backend projects
EJS
2
star
26

pact-consumer-driven-testing

JavaScript
2
star
27

progressive-web-apps

JavaScript
1
star
28

ng2-pdf-viewer-electron-example

TypeScript
1
star
29

DES

Des in c++
C++
1
star
30

pomodoro-timer

Pomodoro timer
JavaScript
1
star
31

local-eye

Techfest hackathon project for MAN and FlixBus
JavaScript
1
star
32

apiprojects

JavaScript
1
star
33

github-actions-for-ci

JavaScript
1
star
34

clown_in_the_cloud

Sensor controlled robot
JavaScript
1
star
35

ilquando

PHP project based on Tonic RESTful Framework + Doctrine + Twig
PHP
1
star
36

react-game-of-life

game of life on react
JavaScript
1
star
37

hello-github-actions

Dockerfile
1
star
38

VadimDez

1
star
39

Learn

C++
1
star
40

a-shuttle

Hackathon project
TypeScript
1
star