mariuszfoltak / angular2-datatable

DataTable - Simple table component with sorting and pagination for Angular2
202 stars 181 forks source link

AngularFire2 FirebaseListObservable mfData #92

Open pedrolucasoliva opened 7 years ago

pedrolucasoliva commented 7 years ago

The [mfData] propertie needs a JSON list.

How can I put my AngularFire2 FirebaseListObservable to work with angular2-datatable? Someone did it?

liam-betsworth commented 7 years ago

@pedrolucasoliva Also having this issue. I managed to get around it by directly accessing the _value property within the Observable.

[mfData]="yourObservable.source._value"

It would be great if mfData accepted an Observable, just like *ngFor does.

liam-betsworth commented 7 years ago

Nevermind – figured it out. You need to use the async pipe to subscribe to an observable or promise. It then unwraps the value each time it updates.

<table [mfData]="topics | async">

vinhWater commented 7 years ago

It takes half of day to work around and finally easily to integrate AngularFirestore and Angular2-datatable. I hope this help.

//Component code

export class AppComponent {
  items: Observable<any[]>;
  constructor(db: AngularFirestore) {
    this.items = db.collection('items').valueChanges();
  }
}

//HTML code

<table class="table table-striped" [mfData]="items | async" #mf="mfDataTable" [mfRowsOnPage]="rowsOnPage" [(mfSortBy)]="sortBy" [(mfSortOrder)]="sortOrder">
...
code everything
...
<tr *ngFor="let item of mf.data"> 

That 's all. Don't add anything into *ngFor , I guess mfData take over for this. Thanks for reading.