MCPcopy Index your code
hub / github.com/VadimDez/ngx-order-pipe

github.com/VadimDez/ngx-order-pipe @3.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 3.0.0 ↗ · + Follow
1,332 symbols 3,980 edges 12 files 10 documented · 1%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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.



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


Result:



{ prop: { list: [1, 2, 3] } }


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

Core symbols most depended-on inside this repo

next
called by 66
docs/main-PGAEETKV.js
get
called by 61
docs/main-PGAEETKV.js
pipe
called by 58
docs/main-PGAEETKV.js
p
called by 57
docs/main-PGAEETKV.js
transform
called by 52
src/app/order-pipe/ngx-order.pipe.ts
g
called by 48
docs/main-PGAEETKV.js
forEach
called by 40
docs/main-PGAEETKV.js
w
called by 40
docs/main-PGAEETKV.js

Shape

Function 844
Method 468
Class 20

Languages

TypeScript100%

Modules by API surface

docs/main-PGAEETKV.js1,181 symbols
docs/polyfills-A7MJM4D4.js132 symbols
src/app/order-pipe/ngx-order.pipe.ts12 symbols
src/app/app.component.ts4 symbols
src/app/order-pipe/ngx-order.module.ts2 symbols
src/app/order-pipe/ngx-order.pipe.spec.ts1 symbols

For agents

$ claude mcp add ngx-order-pipe \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page