VadimDez / ngx-order-pipe

▼ Angular 5+ orderBy pipe
https://vadimdez.github.io/ngx-order-pipe/
MIT License
243 stars 57 forks source link

Refresh orderBy after *ngFor is updated? #23

Closed FahadAlbukhari closed 6 years ago

FahadAlbukhari commented 7 years ago

How to refresh the order automatic on any changes of the *ngFor?

VadimDez commented 7 years ago

orderBy is applied right after array in *ngFor is changed

kkamalesh commented 7 years ago

Hi i used the below code after installing the Ng2OrderModule.but its not ordering the list by the type field.what i am doing wrong please let me know.

<div *ngFor="let favorite of favoriteReports | orderBy: 'favorite.type'" title="{{favorite.title}}" class="row-striped">
  <a [routerLink]="['/report/documentList',{reportId:favorite.id}]"
     *ngIf="favorite.type=='Report'" (click)="selectFavorite(favorite,$event)">
    <i class="fa fa-file-text"></i>&nbsp; {{favorite.title}}</a>
  <a [routerLink]="['/report/', favorite.folderPathId]" *ngIf="favorite.type!='Report'"
     (click)="selectFavorite(favorite,$event)">
    <i class="fa fa-folder-open"></i>&nbsp; {{favorite.title}}</a>
</div>
VadimDez commented 7 years ago

Try to install ngx-order-pipe (see installation and usage in the documentation) instead of ng2-order-pipe.

DigitalMystery commented 6 years ago

The refresh is not working for me either.

*ngFor="let myItem of myObject.myItems | orderBy: 'itemOrder'"

itemOrder is a property off myItem. I had to add the ticks ' for it to work as well which I did not see in the example.

JavanXD commented 6 years ago

@VadimDez The refresh is not working for me either. <li *ngFor="let address of addresses | orderBy:'validFrom':true; let i = index"> validFrom is a prop of address and the type is Date. After adding an address to addresses and also changing the value of a validFrom the list does not reorder as expected.

ESimmonds commented 6 years ago

works if the pipe is stateful

@Pipe({
  name: 'orderBy',
  pure: false
})
VadimDez commented 6 years ago

Fixed in latest version 1.1.0 of ngx-order-pipe.

Thanks @ESimmonds for pointing that out.

ESimmonds commented 6 years ago

Thanks @VadimDez