
Security News
CISA Kills Off RSS Feeds for KEVs and Cyber Alerts
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
ngx-order-pipe
Advanced tools
Order your collection by a field
https://vadimdez.github.io/ngx-order-pipe/
or see code example
https://stackblitz.com/edit/ngx-order-pipe
npm install ngx-order-pipe --save
For Angular lower than 5 use version 1.1.3
In case you're using systemjs
- see configuration here. Otherwise skip this part.
{{ collection | orderBy: expression : reverse : caseInsensitive : comparator }}
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';
}
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>
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 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.
true
)<li *ngFor="let item of array | orderBy: order : false : true">
{{ item.name }}
</li>
false
will do case sensitive comparison to order collection:<li *ngFor="let item of array | orderBy: order : false : false">
{{ item.name }}
</li>
If this project help you reduce time to develop, you can give me a cup of tea :)
FAQs
Angular order pipe, order collection by a field
The npm package ngx-order-pipe receives a total of 17,006 weekly downloads. As such, ngx-order-pipe popularity was classified as popular.
We found that ngx-order-pipe demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.